Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Donna McMaster donnamcmaster

🏠
Working from home
View GitHub Profile
@donnamcmaster
donnamcmaster / wp-piklist-metabox-top-pages-only.php
Last active Apr 6, 2017
WordPress: Make Piklist plugin show metabox only for top-level pages (i.e., post_parent = 0)
View wp-piklist-metabox-top-pages-only.php
<?php
/**
* This code went into the file in piklist/parts/metaboxes
*/
/*
Title: Section Name
Post Type: page
Top pages only: true
*/
@donnamcmaster
donnamcmaster / wp-add-gallery-title-field.php
Last active May 19, 2017
WordPress: set a title attribute in gallery output; some plugins will display this as a caption
View wp-add-gallery-title-field.php
@donnamcmaster
donnamcmaster / wp-post-type-slug-body-class.php
Created Apr 6, 2017
WordPress: adds the post type and slug to the <body> class, e.g., "page-about"
View wp-post-type-slug-body-class.php
<?php
/**
* Adds the post type and slug to the <body> class, e.g., "page-about".
*/
add_filter( 'body_class', function( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[]= "{$post->post_type}-{$post->post_name}";
@donnamcmaster
donnamcmaster / wp-tag-cloud-smaller-fonts.php
Created Apr 6, 2017
WordPress: reduce the font sizes in the tag cloud
View wp-tag-cloud-smaller-fonts.php
<?php
/**
* Reduce the font sizes in the WordPress tag cloud
*/
add_filter( 'widget_tag_cloud_args', function( $args ) {
$args['smallest'] = 11;
$args['largest'] = 24;
$args['unit'] = 'px';
return $args;
});
@donnamcmaster
donnamcmaster / wp-insert-custom-media-sizes.php
Created Apr 7, 2017
WordPress: add custom image sizes to the list of choices in Insert Media.
View wp-insert-custom-media-sizes.php
<?php
/**
* Custom Image Sizes
* - adds all custom image sizes to the list of choices in Insert Media
*/
add_filter( 'image_size_names_choose', function ( $sizes ) {
global $_wp_additional_image_sizes;
if ( !empty( $_wp_additional_image_sizes ) ) {
foreach ( $_wp_additional_image_sizes as $id => $data ) {
if ( !isset( $sizes[$id] ) )
@donnamcmaster
donnamcmaster / wp-widget-shortcode.php
Last active Apr 7, 2017
WordPress: allows you to insert a widget into any content area using a shortcode
View wp-widget-shortcode.php
<?php
/**
* Widget Shortcode
* - allows you to insert a widget into any content area using a shortcode
* - credit: http://wp.smashingmagazine.com/2012/12/11/inserting-widgets-with-shortcodes/
* - read the comments on the Smashing Magazine article for pros and cons of this function
*/
add_shortcode( 'mcw_widget', function ( $atts ) {
// configure defaults and extract the attributes into variables
extract( shortcode_atts(
@donnamcmaster
donnamcmaster / wp-allow-view-post-editing.php
Last active Apr 22, 2018
WordPress: when a post is being edited, give a warning but allow others to view edit screen. Useful for remote training situations.
View wp-allow-view-post-editing.php
if ( is_admin() ) {
// soften post lock to post warning
add_filter( 'show_post_locked_dialog', '__return_false' );
add_filter( 'wp_check_post_lock_window', '__return_false' );
}
@donnamcmaster
donnamcmaster / wp-woocommerce-utility-urls.php
Last active Apr 21, 2019
WordPress: URLs for WooCommerce utility pages (cart, checkout, etc)
View wp-woocommerce-utility-urls.php
<!-- Get and display the My Account page url -->
<?php echo get_permalink( wc_get_page_id( 'checkout' ) ); ?>
<!-- Get and display the Cart page url -->
<?php echo get_permalink( wc_get_page_id( 'cart' ) ); ?>
<!-- Get and display the Shop page url -->
<?php echo get_permalink( wc_get_page_id( 'shop' ) ); ?>
<!-- Get and display the Checkout page url -->
@donnamcmaster
donnamcmaster / icon-from-svg-code.sccs
Created Jul 29, 2018
use Open Iconic SVG definition to define an icon
View icon-from-svg-code.sccs
/* ==========================================================================
SVG to CSS Example: Breadcrumbs "Home Icon"
- an example of using the Open Iconic SVG code to create a "home" icon
- this is the same method as used in the Bootstrap 4 _variables.sccs file
- started by downloading the distro from https://useiconic.com/open
- found the 'home' icon SVG and copied its path code
- then pasted the path code into one of the Bootstrap icon definitions &
changed the fill color
========================================================================== */
$link-color: blue;
@donnamcmaster
donnamcmaster / strip-shortcode-ptags.php
Last active May 1, 2019
WordPress: process content outside the loop; get rid of extra <p> tags around shortcodes
View strip-shortcode-ptags.php
/* props to Thomas Griffin
https://thomasgriffin.io/remove-empty-paragraph-tags-shortcodes-wordpress/
*/
$extra_junk = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']',
']<br>' => ']',
'<p>&nbsp;</p>' => '',