Skip to content

Instantly share code, notes, and snippets.

View donnamcmaster's full-sized avatar
🏠
Working from home

Donna McMaster donnamcmaster

🏠
Working from home
View GitHub Profile
@donnamcmaster
donnamcmaster / wp-widget-shortcode.php
Last active April 7, 2017 21:25
WordPress: allows you to insert a widget into any content area using a shortcode
<?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-insert-custom-media-sizes.php
Created April 7, 2017 20:50
WordPress: add custom image sizes to the list of choices in Insert Media.
<?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-tag-cloud-smaller-fonts.php
Created April 6, 2017 21:59
WordPress: reduce the font sizes in the tag cloud
<?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-post-type-slug-body-class.php
Created April 6, 2017 21:57
WordPress: adds the post type and slug to the <body> class, e.g., "page-about"
<?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-add-gallery-title-field.php
Last active May 19, 2017 05:28
WordPress: set a title attribute in gallery output; some plugins will display this as a caption
@donnamcmaster
donnamcmaster / wp-piklist-metabox-top-pages-only.php
Last active April 6, 2017 22:08
WordPress: Make Piklist plugin show metabox only for top-level pages (i.e., post_parent = 0)
<?php
/**
* This code went into the file in piklist/parts/metaboxes
*/
/*
Title: Section Name
Post Type: page
Top pages only: true
*/