Skip to content

Instantly share code, notes, and snippets.

@seemly
seemly / list-all-registered-gutenberg-blocks.js
Created February 8, 2024 16:13
List all registered WordPress Gutenberg Blocks. Paste this snippet in Chrome Dev Tools Console while in the Gutenberg editor view.
let types = wp.blocks.getBlockTypes();
// filter to just the core blocks
let core_blocks = types.filter(
type => type.name.startsWith('core/')
);
// grab just the names
let block_names = types.map(type => type.name);
@seemly
seemly / wordpress-add-new-column-for-last-modified-date.php
Created April 17, 2023 09:48
Add a new 'Last Modified' column to WordPress admin Post list pages
<?php
function add_new_admin_column($columns)
{
$columns['last_modified'] = 'Last Modified';
return $columns;
}
add_filter('manage_posts_columns', 'add_new_admin_column');
@seemly
seemly / index.php
Created March 28, 2023 10:57
Conditionally hide Google Adsense snippet on a WordPress site using WP Code and ACF
<?php
// Check if ACF function `get_field()` exists. If it doesn't exist, display ads won't be shown.
// If it does exist and ACF 'hide_display_ads' value is not falsey, show display ads.
if(function_exists('get_field') && !get_field('hide_display_ads'))
{
echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-[your-adsense-id]" crossorigin="anonymous"></script>';
}
@seemly
seemly / shortcode-extended.php
Last active May 12, 2023 15:02
Enable the use of ACF shortcodes within the native Query Loop gutenberg block.
<?php
/**
* Shortcode Extended
*
* @package ShortcodeExtended
* @author Chris Sparshott
* @copyright 2022 Chris Sparshott
* @license GPL-2.0-or-later
*
@seemly
seemly / my.cnf
Created May 24, 2021 08:32
Apple M1 - Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Setting up my new Apple M1 macbook pro I was having issues setting up mysql@5.7 using homebrew, with the following message being thrown:
```
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
```
We need to modify the MySQL config file:
```
nano /usr/local/etc/my.cnf
@seemly
seemly / getTextNodes.txt
Last active February 7, 2018 16:58
jQuery - Find object containing direct textNode content
function getTextNodes(cssSelector, findString) {
var items = $(cssSelector)
.contents()
.filter(function() {
var isText = this.nodeType == Node.TEXT_NODE;
if (isText) {
var text = $.trim(this.textContent);
if (text.length && text.indexOf(findString) > -1) {