Skip to content

Instantly share code, notes, and snippets.

View BruceMcKinnon's full-sized avatar

BruceMcKinnon

View GitHub Profile
@BruceMcKinnon
BruceMcKinnon / functions.php
Created May 9, 2022 00:50
Add menu item description to a menu item
//
// Add the menu item description to the visible title.
//
add_filter( 'nav_menu_item_title', 'nav_add_desc', 10, 4);
function nav_add_desc( $title, $menu_item, $args, $depth ) {
$retHtml = '';
$desc = $menu_item->description;
@BruceMcKinnon
BruceMcKinnon / privacy.html
Created February 24, 2022 22:59
Generic Privacy Policy
When you visit [bloginfo show="name"] details of your visit may be logged in the following ways:
<ul>
<li>Standard web server logging</li>
<li>Google Analytics. Google Analytics uses cookies to accumulate analytics data. This analytics data is used for the purpose of determining the volume and types of usage of the [bloginfo show="name"] web site. Details of Google’s usage of this data may be found at <a href="https://policies.google.com/technologies/partner-sites" target="_blank" rel="noopener noreferrer">https://policies.google.com/technologies/partner-sites</a></li>
<li>Error logging generated by components of the [bloginfo show="url"] web site, which may occur from time-to-time.</li>
</ul>
Information logged may include, but may not be limited to:
@BruceMcKinnon
BruceMcKinnon / style.scss
Created February 11, 2022 00:10
Gravity Forms - Turn Radio Buttons into Real Buttons
//
// Make Gravity Forms radio buttons look like normal buttons. Add this SCSS (or convert to CSS) to your WP theme,
// then add the gf_radio_slides class to your radio buttons in the
// Gravity Forms > Editor > Radio Buttons > Appearance > Custom CSS Class
//
//
.gf_radio_slides {
.gfield_radio {
.gchoice {
display: inline-block !important;
#
# Using NVM with multiple versions of NodeJS, use 'prestart' to change the version of NodeJS
#
# https://chamikakasun.medium.com/how-to-manage-multiple-node-versions-in-macos-2021-guide-5065f32cb63b
#
# https://itnext.io/nvm-the-easiest-way-to-switch-node-js-environments-on-your-machine-in-a-flash-17babb7d5f1b
#
# https://stackoverflow.com/questions/34301122/is-there-a-way-to-run-nvm-use-automatically-in-a-prestart-npm-script
#
# For example, the'prestart' command was added to package.js to set the correct version of NodeJS for this FoundationPress build
@BruceMcKinnon
BruceMcKinnon / functions.php
Created August 30, 2021 23:25
Change Wordpress Register Link
add_filter( 'register', 'bl_register_link');
function bl_register_link() {
$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'New Customers - Register Now' ) );
return $registration_url;
}
@BruceMcKinnon
BruceMcKinnon / functions.php
Created August 2, 2021 23:42
Woo disable product lightbox and zoom
//
// Disable the Woo lightbox
//
add_action( 'after_setup_theme', 'bl_disable_wc_lightbox', 100 );
function bl_disable_wc_lightbox() {
remove_theme_support( 'wc-product-gallery-lightbox' );
remove_theme_support( 'wc-product-gallery-zoom' );
}
@BruceMcKinnon
BruceMcKinnon / functions.php
Created August 2, 2021 23:41
Woo Custom Product Add to Cart and Checkout
//
// Shortcode to add a custom Add-To-Cart and Checkout button
//
// Button displays icon, price and product name
//
function bl_add_to_cart_button( $atts ) {
$params = shortcode_atts( array(
'id' => null,
'text' => '{product_name}',
'show_icon' => 1,
@BruceMcKinnon
BruceMcKinnon / functions.php
Created June 10, 2021 06:36
Woocommerce - hide chargable shipping methods when free shipping is available
//
// Hide chargable shipping methods if free shipping is valid
// Thanks to https://flexibleshipping.com/woocommerce-free-shipping-over-amount/
//
function bl_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
@BruceMcKinnon
BruceMcKinnon / functions.php
Created March 25, 2021 03:46
Customise a SimpleLinks list and return as a table
//
// Hook the SimpleLinks plugin output.
// Puts the list into a table to match the site, which includes the post_date and a the 'Source' custom field
//
// Example shortcode call:
//
// [simple-links category="In the Press" fields="pub_date,source" orderby="date" order="DESC" count=5]
//
add_filter('simple_links__output', 'bl_link_out',10,3);
@BruceMcKinnon
BruceMcKinnon / functions.php
Created March 16, 2021 02:50
Add categories to media items
// apply categories to attachments
function add_media_categories() {
register_taxonomy_for_object_type( 'category', 'attachment'
);
}
add_action( 'init' , 'add_media_categories' );