Skip to content

Instantly share code, notes, and snippets.

@FriendlyWP
FriendlyWP / widget-featured-books.php
Last active August 29, 2015 14:16
ACF repeater with nested relationship field, used in widget for ACF Widgets plugin integration (http://acfwidgets.com/). Used on http://julialondon.com/about/ in sidebar to display featured books.
@FriendlyWP
FriendlyWP / functions.php
Last active August 29, 2015 14:19
Dynamically add to Gravity Forms notification email address list (include emails stored in a custom post meta field).
// change # to the id of your form to target a specific form
add_filter( 'gform_notification_#', 'route_notification', 1, 2 );
function route_notification($notification, $form , $entry) {
global $post;
// the $post here is the post where the Form is displayed
$email_to = get_post_meta($post->ID, 'email', true);
if ($email_to){
$notification['to'] .= ',' . $email_to;
}
return $notification;
@FriendlyWP
FriendlyWP / functions.php
Created June 24, 2015 23:03
Get YouTube ID from various url structures
// GET YOUTUBE ID FROM URL
function getYouTubeIdFromURL($url) {
$pattern = '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i';
preg_match($pattern, $url, $matches);
return isset($matches[1]) ? $matches[1] : false;
}
@FriendlyWP
FriendlyWP / functions.php
Created June 25, 2015 16:18
Embed Twitter Cards
// helper function for twitter card stuff
// GET YOUTUBE ID FROM URL
function getYouTubeIdFromURL($url) {
$pattern = '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i';
preg_match($pattern, $url, $matches);
return isset($matches[1]) ? $matches[1] : false;
}
@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: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
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 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;
}