Skip to content

Instantly share code, notes, and snippets.

View mustardBees's full-sized avatar

Phil Wylie mustardBees

View GitHub Profile
<?php
// Example meta box field
$cmb->add_field( array(
'name' => 'Test Select',
'id' => 'test_select',
'type' => 'pw_multiselect',
'options_cb' => 'iweb_get_cmb2_term_options',
'get_terms_args' => array(
'taxonomy' => 'post_tag',
),
@mustardBees
mustardBees / functions.php
Created May 5, 2020 14:04
WordPress WP Search with Algolia plugin - push custom fields to Algolia.
<?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 / functions.php
Created August 27, 2013 21:03
Enqueue Google Maps API and our script to initialise the map
<?php
wp_register_script( 'pw-google-maps-api', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', null, null, true );
wp_enqueue_script( 'pw-store-locations', get_stylesheet_directory_uri() . '/js/store-locations.js', array( 'jquery', 'pw-google-maps-api' ), null, true );
<?php
/**
* Add classes to subcategory images.
*
* @param $category
*/
function kanuka_category_custom_thumbnail( $category ) {
$output = '';
ob_start();
woocommerce_subcategory_thumbnail( $category );
<?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
Last active August 11, 2021 14:40
Filter a few parameters into WordPress YouTube oEmbed requests. Enable modest branding which hides the YouTube logo. Remove the video title and uploader information. Prevent related videos from being shown once the video has played.
<?php
/**
* Filter a few parameters into YouTube oEmbed requests
*
* @link http://goo.gl/yl5D3
*/
function iweb_modest_youtube_player( $html, $url, $args ) {
return str_replace( '?feature=oembed', '?feature=oembed&modestbranding=1&showinfo=0&rel=0', $html );
}
add_filter( 'oembed_result', 'iweb_modest_youtube_player', 10, 3 );
@mustardBees
mustardBees / functions.php
Created May 11, 2021 10:03
Filter Jetpack widget visibility page list - include all pages, not just those which are published.
<?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;
<?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 ) {
@mustardBees
mustardBees / formidable-prepopulate-from-cookie.php
Last active March 23, 2021 18:50
Prepopulate fields across forms with previously entered values.
<?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
*/