Skip to content

Instantly share code, notes, and snippets.

@FriendlyWP
FriendlyWP / posts-to-posts-list-widget.php
Created November 23, 2012 18:15
Posts 2 Posts List Widget
<?php
/*
Plugin Name: Posts 2 Posts List Widget
Plugin URI: http://friendlywebconsulting.com/
Description: Creates a widget to display posts connected via the Posts 2 Posts plugin by Scribu, found here: http://wordpress.org/extend/plugins/posts-to-posts/
Author: Michelle McGinnis
Author URI: http://friendlywebconsulting.com/
Version: 1.0.0-alpha
*/
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 00:44
Display content with a word limit
/**
* Display specified content with a word limit
* Can be used for excerpts, full content, etc.
* In your theme file, use thus to display 40 words of the excerpt:
* $excerpt = get_the_excerpt();
* echo string_limit_words( $excerpt, 40 );
*
* @param string $string A variable containing the content you wish to display.
* @param num $word_limit The number of words to display.
* @return string Content limited to the number of words specified.
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 00:49
WordPress SEO by Yoast tweaks
// FILTER WORDPRESS SEO BY YOAST outputs in the WordPress control panel
// remove WP-SEO columns from edit-list pages in admin
add_filter( 'wpseo_use_page_analysis', '__return_false' );
// put WP-SEO panel at bottom of edit screens (low priority)
add_filter('wpseo_metabox_prio' , 'my_wpseo_metabox_prio' );
function my_wpseo_metabox_prio() {
return 'low' ;
}
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 00:52
Bold words in widget titles using underscore + asterisk (_* word *_).
// REPLACE _* *_ WITH <STRONG> HTML IN WIDGET TITLES
// usage: _*This*_ word is bold
add_filter( 'widget_title', function($title) {
$title = str_replace('_*', '<strong>', $title);
$title = str_replace('*_', '</strong>', $title);
return $title;
} );
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 00:54
Shortcode to insert current year.
/* SHORTCODE WHICH INSERTS CURRENT YEAR
* usage: [year]
*/
add_shortcode('year', 'year_shortcode');
function year_shortcode() {
$year = date('Y');
return $year;
}
@FriendlyWP
FriendlyWP / functions.php
Last active March 22, 2016 23:26
Mailto email obfuscation shortcode. For anti-spam (spam-bots, spam fix, email mailto).
/* SHORTCODE FOR EMAIL OBFUSCATION
* usage: [email]myaddress@domain.com[/email]
* OR: [email address="myaddress@domain.com"]Contact Us[/email]
*/
add_shortcode('email', 'emailbot_ssc');
function emailbot_ssc($atts, $content = null) {
extract( shortcode_atts( array(
'address' => '',
), $atts ) );
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 01:29
Add custom default avatar
// 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;
}
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 01:30
Enable shortcodes in all widgets
// ENABLE SHORTCODES IN ALL TEXT WIDGETS
add_filter('widget_text', 'do_shortcode');
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 01:32
Remove widget title if it begins with an exclamation point (!)
// 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 );
}
@FriendlyWP
FriendlyWP / functions.php
Created October 26, 2013 01:39
Display custom image sizes in Media uploader; insert custom image sizes into posts and pages
// 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'),
) );
}