Skip to content

Instantly share code, notes, and snippets.

@kraftbj
kraftbj / functions.php
Created January 31, 2014 18:49
Use image from the latest post for the og:image tag on the home page
<?php
function fb_home_image( $tags ) {
if ( is_home() ) {
$latest_post = get_posts("post_type=post&numberposts=1");
$latest_post = $latest_cpt[0]->ID;
if ( class_exists( 'Jetpack_PostImages' ) ) {
$post_images = Jetpack_PostImages::get_images( $latest_post, array( 'width' => 200, 'height' => 200 ) );
if ( $post_images && !is_wp_error( $post_images ) ) {
$image = array();
@kraftbj
kraftbj / functions.php
Last active August 29, 2015 13:56
Add publicize support to the WooCommerce Product CPT
<?php
add_action('init', 'kraft_woo_publicize');
function kraft_woo_publicize() {
add_post_type_support( 'product', 'publicize' );
}
@kraftbj
kraftbj / functions.php
Last active August 29, 2015 13:56
Deactivate photon only on a specific page. Example assumes page_id 2.
<?php
function no_livecam_photon() {
if ( is_page( 2 ) ) {
add_filter( 'jetpack_photon_skip_image', '__return_true');
}
}
add_action('wp', 'no_livecam_photon');
<?php
/*
* Plugin Name: Very Simple Pinterest Plugin
*/
function bk_vspp() {
echo '<script type="text/javascript" async data-pin-height="28" data-pin-hover="true" src="//assets.pinterest.com/js/pinit.js"></script>';
}
add_action( 'wp_footer', 'bk_vspp');
@kraftbj
kraftbj / functions.php
Created February 24, 2014 23:03
Re-add sharing buttons under post content
function sp_share_buttons_below_post( $post_meta ) {
if ( is_single() ) {
return sharing_display().$post_meta;
}
}
add_filter( 'genesis_post_meta', 'sp_share_buttons_below_post', 10);
@kraftbj
kraftbj / functions.php
Created March 8, 2014 15:00
Change the twitter:site tag in Jetpack <3.0. Add to functions.php or a core functionality plugin.
function tweakjp_custom_twitter_site( $og_tags ) {
$og_tags['twitter:site'] = '@kraft';
return $og_tags;
}
add_filter( 'jetpack_open_graph_tags', 'tweakjp_custom_twitter_site', 11 );
@kraftbj
kraftbj / functions.php
Created March 17, 2014 03:12
IS for G HTML 4
/**
* Add support for Jetpack infinite scroll
**/
function kraft_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'footer_widgets' => 'footer-1',
'render' => 'genesis_do_loop',
'footer' => 'footer'
) );
@kraftbj
kraftbj / functions.php
Created March 27, 2014 17:24
Disabled Related Posts from appearing on specific posts
<?php
function jetpackme_no_related_posts( $options ) {
if ( is_single( array( 17, 19, 1, 11 ) ) ) { // specific post IDs by number, or slug/post title in quotes
$options['enabled'] = false;
}
return $options;
}
add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_no_related_posts' );
@kraftbj
kraftbj / functions.php
Created April 1, 2014 21:07
Filter the returned related posts output to for posts only in the last 2 months.
function jetpackme_related_posts_past_year_only( $date_range ) {
$date_range = array(
'from' => strtotime( '-2 months' ),
'to' => time(),
);
return $date_range;
}
add_filter( 'jetpack_relatedposts_filter_date_range', 'jetpackme_related_posts_past_year_only' );
@kraftbj
kraftbj / functions.php
Created April 17, 2014 21:42
Disabled Related Posts when using the mobile theme
$jetpack_active_modules = get_option('jetpack_active_modules');
if ( class_exists( 'Jetpack', false ) && $jetpack_active_modules && in_array( 'minileven', $jetpack_active_modules ) && jetpack_is_mobile() ) {
function jetpackme_no_related_posts_mobile( $options ) {
if ( is_single( array( 17, 19, 1, 11 ) ) ) {
$options['enabled'] = false;
}
return $options;
}
add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_no_related_posts_mobile' );
}