This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
**** LIMIT WORDS IN EXCERPTS (or any supplied content) | |
Usage: | |
$text = get_the_excerpt(); | |
echo string_limit_words($text, 40); | |
*/ | |
function string_limit_words($string, $word_limit) { | |
$words = explode(' ', $string, ($word_limit + 1)); | |
if(count($words) > $word_limit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$custom_terms = get_terms('custom_taxonomy'); | |
foreach($custom_terms as $custom_term) { | |
wp_reset_query(); | |
$args = array( | |
'post_type' => 'custom_post_type', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'custom_taxonomy', | |
'field' => 'slug', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************** ADD FILE TYPES TO MEDIA LIBRARY FILTERS ****************/ | |
add_filter( 'post_mime_types', 'custom_mime_types' ); | |
function custom_mime_types( $post_mime_types ) { | |
$post_mime_types['application/msword'] = array( __( 'Word Docs' ), __( 'Manage Word Docs' ), _n_noop( 'Word Docs <span class="count">(%s)</span>', 'Word Docs <span class="count">(%s)</span>' ) ); | |
$post_mime_types['application/vnd.ms-excel'] = array( __( 'Excel Files' ), __( 'Manage Excel Files' ), _n_noop( 'Excel Files <span class="count">(%s)</span>', 'Excel Files <span class="count">(%s)</span>' ) ); | |
$post_mime_types['application/vnd.ms-powerpoint'] = array( __( 'PowerPoint Files' ), __( 'Manage PowerPoint Files' ), _n_noop( 'PowerPoint Files <span class="count">(%s)</span>', 'PowerPoint Files <span class="count">(%s)</span>' ) ); | |
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDFs <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) ); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AUTOMATICALLY ADD ALT TAGS TO IMAGES | |
add_filter('the_content', 'add_alt_tags', 99999); | |
function add_alt_tags($content) | |
{ | |
global $post; | |
preg_match_all('/<img (.*?)\/>/', $content, $images); | |
if(!is_null($images)) | |
{ | |
foreach($images[1] as $index => $value) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VIDEO | |
// remove dimensions from oEmbed videos | |
add_filter( 'embed_oembed_html', 'tdd_oembed_filter', 10, 4 ) ; | |
function tdd_oembed_filter($html, $url, $attr, $post_ID) { | |
$return = '<figure class="video-container">'.$html.'</figure>'; | |
return $return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allows users to insert your custom image sizes via the Add Media button | |
// In this example, two custom image sizes are added to the defaults | |
add_filter( 'image_size_names_choose', 'my_custom_sizes' ); | |
function my_custom_sizes( $sizes ) { | |
return array_merge( $sizes, array( | |
'thumb-narrow' => __('Narrow Thumbnail'), | |
'thumb-wide' => __('Wide Thumbnail'), | |
) ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REMOVE WIDGET TITLE IF IT BEGINS WITH EXCLAMATION POINT | |
// To use, add a widget and in the Title field put !The title here | |
// The title will show in the control panel, but not on the site itself | |
add_filter( 'widget_title', 'remove_widget_title' ); | |
function remove_widget_title( $widget_title ) { | |
if ( substr ( $widget_title, 0, 1 ) == '!' ) | |
return; | |
else | |
return ( $widget_title ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ENABLE SHORTCODES IN ALL TEXT WIDGETS | |
add_filter('widget_text', 'do_shortcode'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add a new default avatar to the list in WordPress admin | |
// change path to reflect where your default image lives | |
add_filter( 'avatar_defaults', 'mytheme_addgravatar' ); | |
function mytheme_addgravatar( $avatar_defaults ) { | |
$myavatar = get_bloginfo('stylesheet_directory') . '/_/images/avatar.gif'; | |
$avatar_defaults[$myavatar] = 'New Default Gravatar'; | |
return $avatar_defaults; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* SHORTCODE FOR EMAIL OBFUSCATION | |
* usage: [email][email protected][/email] | |
* OR: [email address="[email protected]"]Contact Us[/email] | |
*/ | |
add_shortcode('email', 'emailbot_ssc'); | |
function emailbot_ssc($atts, $content = null) { | |
extract( shortcode_atts( array( | |
'address' => '', | |
), $atts ) ); |