Hook of the Month: Customize Related Posts

Jetpack’s Related Posts module is a simple and easy way to add contextual posts your visitors might be interested in when they reach the end of a post on your website. To use this feature, go to your site’s Jetpack settings and enable the module. All the magic happens behind the scenes, on the WordPress.com cloud: Jetpack’s natural language search engine scans all of your posts, analyzes all their content based on several factors, and returns a list of related posts for each one of your posts.

Now that Jetpack has worked its magic1, let’s discover how to customize those related posts or how to customize their display on your site.

Related Cats

Use filters to customize how Related Posts are displayed on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , | 4 Comments

Announcing: developer.jetpack.com

Do you use hooks to customize Jetpack’s default behaviour? Are you a fan of our Hook of the Month series? Then you’ll love our new code reference!

Jetpack for developers

Continue reading → Announcing: developer.jetpack.com

Posted in Code snippets, Tips & Tricks | Tagged , , | Comments Off on Announcing: developer.jetpack.com

Hook of the Month: Customize Modules, Shortcodes, and Widgets

Whether you’re a blogger, a business owner, or a developer – Jetpack comes with many different features you can use to build your site, write your posts, and promote them. However, you may not use all of these features. This month, we’ll discover how to use filters to customize the list of features added by Jetpack.

Photo: Andrewfhart / Flickr

Photo: Andrewfhart / Flickr

Use filters to customize the Jetpack features available on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , , | 1 Comment

Hook of the Month: Customizing Sharing Buttons

Jetpack’s sharing buttons look good, are simple to use, and include several hooks allowing you to customize every single aspect of the module. Let’s learn to use some of these hooks together!

Use filters to customize sharing buttons on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , | 11 Comments

Hook of the Month: Customizing Contact Forms

Did you know you could create contact forms with Jetpack? This month, we’ll discover different ways to customize these forms on your site.

Use filters to customize Contact Forms on your site

Posted in Code snippets, Tips & Tricks | Tagged , , , , | 5 Comments

Hook of the Month: taking control of email subscriptions

Are you familiar with Jetpack Subscriptions? This month, we’ll use filters to customize this module, and control which posts should be sent to your subscribers.

Jetpack’s Subscriptions module sends an email to your subscribers every time you publish a new post. That’s practical, but sometimes you may not want to bother your subscribers for something that might not be interesting to them.

Use filters to take control of Jetpack Subscriptions

Posted in Code snippets, Tips & Tricks | Tagged , , , , , | 13 Comments

Hook of the Month: Customizing the Top Posts & Pages Widget

Let’s kick off 2016 with a new series: welcome to the first installment of Hook of the Month!

Hooks are places in WordPress code where you can add your own code or change the default behavior of WordPress. Jetpack includes many of those hooks — 430 at the time of writing. In this series, I’ll introduce you to a new hook every month.

Today, let’s look at hooks help you customize one of our most popular widgets, the Top Posts & Pages widget.

Continue reading → Hook of the Month: Customizing the Top Posts & Pages Widget

Posted in Code snippets, Spotlight, Tips & Tricks | Tagged , , , , , , | 28 Comments

How to exclude a category from the Mobile Theme

If you’ve ever wanted to exclude a particular category of posts from being displayed by Jetpack’s Mobile Theme, you can use the following code in your theme’s functions.php or in a functionality plugin:

// Check if we are on mobile
function jetpackme_is_mobile() {
 
    // Are Jetpack Mobile functions available?
    if ( ! function_exists( 'jetpack_is_mobile' ) )
        return false;
 
    // Is Mobile theme showing?
    if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'false' )
        return false;
 
    return jetpack_is_mobile();
}
 
// Modify the main query on the home page for the mobile theme.
function jetpackme_modify_main_query( $arg ) {
    if ( jetpackme_is_mobile() && is_home() ) {
         $arg -> set( 'cat', '-1' );
    }
}
add_action( 'pre_get_posts', 'jetpackme_modify_main_query' );

You would need to replace the 1 in

$arg -> set( 'cat', '-1' );

with the ID of the category you want to exclude.

Looking for more mobile tips? You’ll find them here! And if you more general need help with the Mobile Theme, take a look at our support doc.

Posted in Code snippets, Tips & Tricks | Tagged , , | Comments Off on How to exclude a category from the Mobile Theme

How to add a default fallback image if no image can be found in a post

When you publish a new post on your site, Jetpack crawls it and looks for images that can be used when sharing that post on Facebook, on Twitter, or if that post appears in the Top Posts and Pages widget in your sidebar.

Jetpack starts by looking for a Featured Image. If you didn’t define any, we will look for slideshows and galleries, and then for any images that may be attached to the post. If we don’t find any image attached to that post, we’ll look for single images you may have inserted in the post. If you’ve inserted an image that is hosted on another site, we can use it too.

However, sometimes you may not have added any image to your post. In such cases, you can add this code snippet to your theme’s functions.php file, or in a functionality plugin. This way, your readers will see a default image when sharing that post on Facebook, for example:

function jeherve_custom_image( $media, $post_id, $args ) {
	if ( $media ) {
		return $media;
	} else {
		$permalink = get_permalink( $post_id );
		$url = apply_filters( 'jetpack_photon_url', 'YOUR_LOGO_IMG_URL' );
	
		return array( array(
			'type'	=> 'image',
			'from'	=> 'custom_fallback',
			'src'	=> esc_url( $url ),
			'href'	=> $permalink,
		) );
	}
}
add_filter( 'jetpack_images_get_images', 'jeherve_custom_image', 10, 3 );

It’s worth noting that the fallback image has to be larger than 200 x 200px, as per Facebook requirements. If your image is smaller, Facebook will ignore it.

Reference

Posted in Code snippets, Tips & Tricks | Tagged , , , , | Comments Off on How to add a default fallback image if no image can be found in a post

Ever accidentally publicize a post that you didn’t mean to?

Ever accidentally publicize a post that you didn’t mean to? This snippet will prevent the connections from being auto-selected, so you need to manually select them if you’d like to publicize something.

add_filter( 'publicize_checkbox_default', '__return_false' );

You can place this code snippet in your theme’s functions.php file, or in a functionality plugin.

Posted in Code snippets, Tips & Tricks | Tagged , | 5 Comments
  • Recent Comments

    Jeremy on Jetpack 4.3 and 4.3.1: A faste…
    Jeremy on Jetpack 4.3 and 4.3.1: A faste…
    Jeremy on Jetpack 4.3 and 4.3.1: A faste…
    Jeremy on Jetpack 4.3 and 4.3.1: A faste…
    Jeremy on Jetpack 4.3 and 4.3.1: A faste…
  • Archives

  • Enter your email address to follow this blog and receive notifications of new posts by email.

  • Install Jetpack to see our lineup of features.

    Install Jetpack Now

    Don’t need all Jetpack’s features? No problem. Only activate what you need!