Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Sami Keijonen samikeijonen

🏠
Working from home
View GitHub Profile
@samikeijonen
samikeijonen / block-variations.js
Last active May 17, 2020
Example Block Variations
View block-variations.js
// WordPress dependencies.
const { __ } = wp.i18n;
const { Path, SVG } = wp.components;
/**
* Block variants.
*/
wp.domReady(() => {
wp.blocks.unregisterBlockVariation('core/columns', 'two-columns-equal');
View gist:72929fea16e78d19ec6ce1acc086bf46
import debounce from 'lodash.debounce';
const { subscribe, dispatch, select, withSelect } = wp.data;
const { getEditedPostAttribute, isCurrentPostPublished, getCurrentPostType } = select( 'core/editor' );
const { isTyping } = select( 'core/block-editor' );
const { getMedia } = select( 'core' );
const { lockPostSaving, unlockPostSaving } = dispatch( 'core/editor' );
const { createNotice, removeNotice } = dispatch( 'core/notices' );
const { __ } = wp.i18n;
@samikeijonen
samikeijonen / settings.json
Last active Feb 19, 2019
VS Code workspace settings for PHPCS in 10up projects
View settings.json
{
"phpcs.executablePath": "/absolute-path-to/vendor/bin/phpcs",
"phpcs.standard": "10up-Default",
"phpcs.autoConfigSearch": false
}
@samikeijonen
samikeijonen / gutenberg-notes.md
Last active Jul 7, 2018
Gutenberg notes 7.7.2018
View gutenberg-notes.md

Gutenberg notes

Paragraph

  • In the editor I see inline styles when changing custom size.
  • Also editor styles should use is-small-text, is-larger-text classes so that they would match what theme wants.
@samikeijonen
samikeijonen / filter-pagination-markup.php
Created Jun 27, 2018
Filter pagination markup. And some wp_link_pages_link.
View filter-pagination-markup.php
<?php
add_filter( 'navigation_markup_template', function( $template, $class ) {
// Set custom modifier classes.
$class = 'pagination' === $class ? 'posts' : 'comments';
// Modified template with custom classes.
$template = '
<nav class="pagination pagination--' . $class . '" role="navigation">
<h2 class="screen-reader-text">%2$s</h2>
<div class="pagination__items">%3$s</div>
@samikeijonen
samikeijonen / register-page-template.php
Last active Jun 6, 2018
Register page template in HC5
View register-page-template.php
<?php
use function Hybrid\register_object_template;
add_action( 'hybrid/register_object_templates', function() {
register_object_template( 'example', [
'label' => __( 'Example' ),
'filename' => 'example.php'
] );
@samikeijonen
samikeijonen / align-full-wide.css
Created Mar 17, 2018
Align full and wide CSS example for WP editor
View align-full-wide.css
// Align full and wide.
.alignfull {
margin-left: calc(50% - 50vw);
margin-right: calc(50% - 50vw);
max-width: 1000%;
width: auto;
}
@media (min-width: $breakpoint-1) {
View semantic-html.html
<!DOCTYPE html>
<html>
<head>
<title>Semantic HTML</title>
</head>
<body>
<header>
<nav>
<ul>
View polylang-all-languages.php
<?php
function valteri_pre_get_posts( $query ) {
// Show only posts from 'blogi' category.
if ( ! is_admin() && $query->is_main_query() && is_home() ) {
// Get Finnish ID.
$lang_fi = get_term_by( 'slug', 'fi', 'language' );
$id_fi = $lang_fi->term_id;
// Get Swedish ID.
$lang_sv = get_term_by( 'slug', 'sv', 'language' );
@samikeijonen
samikeijonen / translate-only-terms.php
Last active Dec 10, 2017
Translate only terms from taxonomy "contact_area" when filterin "contact" post type posts. Posts are not translates at all because they only have name, email, and phone number.
View translate-only-terms.php
<?php
$terms = get_terms( array(
'taxonomy' => 'contact_area',
'hide_empty' => false, // Other than default language don't have any posts.
'orderby' => 'name',
'lang' => function_exists( 'pll_current_language' ) ? pll_current_language() : '',
) );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) :
foreach ( $terms as $term ) :
You can’t perform that action at this time.