Skip to content

Instantly share code, notes, and snippets.

Avatar

Florian Brinkmann florianbrinkmann

View GitHub Profile
@florianbrinkmann
florianbrinkmann / functions.php
Created Mar 13, 2021
Add has-\d-columns class to columns blocks after 5.3 update.
View functions.php
<?php
/**
* Add has-\d-columns class to columns blocks after 5.3 update.
*
* @param string $block_content The block content about to be appended.
* @param array $block The full block, including name and attributes.
*
* @return string
*/
add_filter( 'render_block', function( $block_content, $block ) {
@florianbrinkmann
florianbrinkmann / index.js
Last active May 17, 2020
Set attribute `maxWidth` for inner blocks of `slug/slider` block depending on block position in the editor. https://florianbrinkmann.com/block-attribute-abhaengig-block-position-11307/
View index.js
const {
select,
} = wp.data;
wp.domReady( () => {
/**
* Get the slider blocks.
*
* @param {object} block
* @param {array} sliderBlocks
View index.js
/**
* Add categories attribute to core/latest-posts block.
*
* @param {*} settings
* @param {*} name
*/
function latestPostsCategories( settings, name ) {
// Only modify latest posts block settings.
if ( name !== 'core/latest-posts' ) {
return settings;
View restore-favicon-handling.php
<?php
/**
* Do not show favicon (prevents WP logo from showing up since WP 5.4).
* Does NOT show a maybe-existent site icon instead. For that, look here: https://gist.github.com/webdados/a7702e588070f9a1cfa12dff89b3573c
*/
add_action( 'do_faviconico', function() {
header( 'Content-Type: image/vnd.microsoft.icon' );
exit;
} );
View functions.php
<?php
/**
* Add skip-lazy class to first image in content.
*/
add_filter( 'the_content', function( $content ) {
// Check if we have no content.
if ( empty( $content ) ) {
return $content;
}
@florianbrinkmann
florianbrinkmann / index.js
Last active May 24, 2021
Gutenberg FormTokenField block with posts as source
View index.js
/**
* External dependencies
*/
const { isUndefined, pickBy } = lodash;
/**
* WordPress dependencies
*/
const {
registerBlockType,
View gutenberg-blocks-split
<?
$main_img_wppath = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full')[0];
$portfolio_cats = get_the_term_list( $post->ID, 'portfolio_category', '', ', ');
// declaring all possible custom fields (usually only some of them are populated in the portfolio page)
$portfolioPostIcon = get_post_meta($post->ID, 'portfolioPostIcon', true);
$customers = get_post_meta($post->ID, 'customers', true);
$relnotes = get_post_meta($post->ID, 'relnotes', true);
$appstore = get_post_meta($post->ID, 'appstore', true);
View index.js
import classnames from 'classnames';
import { textColors, backgroundColors } from '../colors';
const {
registerBlockType,
} = wp.blocks;
const {
InspectorControls,
InnerBlocks,
View index.js
import classnames from 'classnames';
const {
registerBlockType,
} = wp.blocks;
const {
InspectorControls,
InnerBlocks,
withColors,
getColorClass
@florianbrinkmann
florianbrinkmann / functions.php
Created May 2, 2018
Remove lightbox script from Hannover WordPress theme.
View functions.php
<?php
add_action( 'wp_enqueue_scripts', 'hannover_child_remove_lightbox', 100 );
/**
* Remove the Hannover lightbox script.
*/
function hannover_child_remove_lightbox() {
wp_dequeue_script( 'hannover-lightbox' );
wp_deregister_script( 'hannover-lightbox' );
}