Skip to content

Instantly share code, notes, and snippets.

View samikeijonen's full-sized avatar
🏠
Working from home

Sami Keijonen samikeijonen

🏠
Working from home
View GitHub Profile
@samikeijonen
samikeijonen / theme.json
Last active July 25, 2023 20:38
theme.json example for WP 5.9
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"custom": {
"color": {
"primary": {
"100": "hsl(360, 100%, 97%)",
"200": "hsl(360, 82%, 89%)",
"300": "hsl(360, 77%, 78%)",
/**
* Set dataLayer for Piwik Pro.
*/
function dataLayer() {
window.dataLayer = window.dataLayer || [];
// Form field have been added as hidden field in the Gravity Form.
// It has class `js-datalayer-name`.
const formNameField = document.querySelector('.js-datalayer-name input');
if (formNameField) {
pipelines:
default:
- parallel:
- step:
image: composer:2.0
name: 'PHPCS'
script:
# Install Dependencies
- composer install
# Run PHPCS
@samikeijonen
samikeijonen / multisite-user-meta.php
Last active May 18, 2022 00:12
Example plugin for using multisite user meta
<?php
/**
* Plugin Name: Multisite User Meta
* Plugin URI: https://foxland.fi/user-meta-in-wordpress-multisite/
* Description: Test multisite user meta with text value.
* Version: 1.0.0
* Author: Sami Keijonen
* Author URI: https://foxland.fi/
* Text Domain: multisite-user-meta
* Domain Path: /languages
@samikeijonen
samikeijonen / social-menu.php
Last active April 14, 2022 17:35
SVG social menu markup
<nav class="menu-social social-navigation menu" role="navigation">
<?php wp_nav_menu(
array(
'theme_location' => 'social',
'container_class' => 'social-menu-wrapper',
'menu_id' => 'menu-social-items',
'menu_class' => 'menu-social-items',
'depth' => 1,
'link_before' => '<span class="screen-reader-text">',
@samikeijonen
samikeijonen / align-full-wide.css
Created March 17, 2018 07:10
Align full and wide CSS example for WP editor
// 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) {
@samikeijonen
samikeijonen / fetch-rest-api.js
Last active April 30, 2021 10:47
Using Fetch API and REST API
/*
* Load contacts and filter by categories.
*/
( function() {
'use strict';
// Variables.
const filterForm = document.getElementById( 'filter-contacts' );
const contactWrapper = document.getElementById( 'contact-section' );
const htmlOutput = document.getElementById( 'js-contact-replace' );
@samikeijonen
samikeijonen / block-variations.js
Last active May 17, 2020 12:29
Example Block Variations
// WordPress dependencies.
const { __ } = wp.i18n;
const { Path, SVG } = wp.components;
/**
* Block variants.
*/
wp.domReady(() => {
wp.blocks.unregisterBlockVariation('core/columns', 'two-columns-equal');
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 / attendee-list.php
Last active December 17, 2019 06:06
Display posts by alphabetical order in a way that first letter of each name is presented.
<?php
/**
* Display 'attendee' post type in alphabetical order by it's category.
*
* The output looks like this:
*
* A
* Ace Bill
* Alb Nick