Skip to content

Instantly share code, notes, and snippets.

View functions.php
<?php
/**
* Add classes to subcategory images.
*
* @param $category
*/
function kanuka_category_custom_thumbnail( $category ) {
$output = '';
ob_start();
woocommerce_subcategory_thumbnail( $category );
View functions.php
<?php
/**
* Add a class to tags.
*
* @param string $html The HTML content.
* @param array $tags List of HTML tags to add a class to.
* @param string $class The class to add.
* @param bool $exception Optional. If the exception value has been defined, it'll take precedence.
*
* @return array|string|string[]|null
@mustardBees
mustardBees / functions.php
Created May 11, 2021
Filter Jetpack widget visibility page list - include all pages, not just those which are published.
View functions.php
<?php
/**
* Filter Jetpack widget visibility page list - include all pages, not just those which are published.
*
* @param stdClass[] $pages Array of objects containing only the ID, post_parent, and post_title fields.
* @param array $parsed_args Array of get_pages() arguments.
*/
function iweb_jetpack_widget_visibility_get_pages( $pages, $parsed_args ) {
global $wpdb;
View functions.php
<?php
/**
* Yoast SEO breadcrumbs - link directly to child page when the parent has our
* "first child redirect" template.
*
* @param array $crumbs The complete list of breadcrumbs.
*
* @return array
*/
function kanuka_wpseo_breadcrumbs_first_child_redirect( $crumbs ) {
View list-image-urls-from-attachment-ids.php
<?php
/*
Plugin Name: List Image URLs From Attachment IDs
Plugin URI: https://www.philwylie.co.uk/
Description: Generate list of original attachment file URLs from a list of attachment IDs. Download using something like Tab Save - https://link.from.pw/3veCu6q
Version: 1.0.0
Author: Phil Wylie
Author URI: https://www.philwylie.co.uk/
License: GPL2
*/
@mustardBees
mustardBees / cmd.sh
Created May 11, 2020
WordPress clear oEmbed cache (YouTube etc.) for all posts/pages using WP-CLI
View cmd.sh
wp post list --post_type=post,page --field=ID | xargs -n1 -I % wp embed cache clear %
@mustardBees
mustardBees / functions.php
Created May 5, 2020
WordPress WP Search with Algolia plugin - push custom fields to Algolia.
View functions.php
<?php
/**
* Push custom fields to Algolia.
*
* @param array $attributes
* @param WP_Post $post
*
* @return array
*/
function iweb_algolia_product_attributes( array $attributes, WP_Post $post ) {
@mustardBees
mustardBees / cmd.sh
Created Apr 30, 2020
Run Yoast SEO 14.0's WP CLI command across all sites on a WordPress network (multisite)
View cmd.sh
wp site list --field=url | xargs -n1 -I % wp --url=% yoast index
@mustardBees
mustardBees / list-variable-products.php
Created Mar 24, 2020
Generate list of WooCommerce variable products.
View list-variable-products.php
<?php
/*
Plugin Name: List Variable Products
Plugin URI: https://www.philwylie.co.uk/
Description: Generate list of WooCommerce variable products.
Version: 1.0.0
Author: Phil Wylie
Author URI: https://www.philwylie.co.uk/
License: GPL2
*/
@mustardBees
mustardBees / functions.php
Created Feb 26, 2020
Prevent LearnDash certificates from being edited.
View functions.php
<?php
/**
* Prevent LearnDash certificates from being edited.
*
* @param $pdf
*/
function iweb_learndash_certification_created( $pdf ) {
$pdf->SetProtection( array( 'modify' ), '', '#:EcjN7P(sGjF*6L', 0, null );
}
add_action( 'learndash_certification_created', 'iweb_learndash_certification_created' );