Skip to content

Instantly share code, notes, and snippets.

View florianbrinkmann's full-sized avatar

Florian Brinkmann florianbrinkmann

View GitHub Profile
@florianbrinkmann
florianbrinkmann / functions.php
Created March 13, 2021 12:55
Add has-\d-columns class to columns blocks after 5.3 update.
<?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 15:40
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/
const {
select,
} = wp.data;
wp.domReady( () => {
/**
* Get the slider blocks.
*
* @param {object} block
* @param {array} sliderBlocks
/**
* 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;
<?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;
} );
<?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 October 24, 2024 11:59
Gutenberg FormTokenField block with posts as source
/**
* External dependencies
*/
const { isUndefined, pickBy } = lodash;
/**
* WordPress dependencies
*/
const {
registerBlockType,
<?
$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);
import classnames from 'classnames';
import { textColors, backgroundColors } from '../colors';
const {
registerBlockType,
} = wp.blocks;
const {
InspectorControls,
InnerBlocks,
import classnames from 'classnames';
const {
registerBlockType,
} = wp.blocks;
const {
InspectorControls,
InnerBlocks,
withColors,
getColorClass
@florianbrinkmann
florianbrinkmann / functions.php
Created May 2, 2018 15:00
Remove lightbox script from Hannover WordPress theme.
<?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' );
}