Jetpack: how to deal with missing images in the Related Posts module

Jetpack Related Posts are great. You should use them!

They are also customizable; we added a lot of filters to allow you to customize the output of the Related Posts. You can find a lot of examples here: Customize Related Posts (Kudos to Xiao for all the great work he’s done with Jetpack Related Posts).

The module also includes an option to “use a large and visually striking layout”. When that option is active, Jetpack will look for a large image (at least 350*200px) in your posts, and use that image when displaying Related Posts. It looks great, and I use it on this site:

Related Posts

What doesn’t look that good, however, is when some of the Related Posts don’t have any image.

Missing Related Image

There are 2 ways to solve this small issue.

Continue reading Jetpack: how to deal with missing images in the Related Posts module

Jetpack: remove a post from the Top Posts Widget

If you use the Jetpack plugin, you’re probably familiar with the Stats module. Once you’ve activated the module, you can also use the Top Posts widget to display a list of the most popular posts on your site.

But what if there is one post that you never want to display there, even if it’s a popular one? You can exclude specific posts from the widget thanks to the jetpack_widget_get_top_posts filter.

To do so, paste the following code into a functionality plugin:

function jeherve_remove_post_top_posts( $posts, $post_ids, $count ) {
	foreach ( $posts as $k => $post ) {
		// Replace 1215 by the ID of the Post you want to remove
		if ( '1215' == $post['post_id'] ) {
			unset( $posts[$k] );
		}
	}
	return $posts;
}
add_filter( 'jetpack_widget_get_top_posts', 'jeherve_remove_post_top_posts', 10, 3 );

Get a headstart with install.php & Jetpack – Timișoara WordPress Meetup

I was invited to Timișoara to give a talk about Jetpack, and got to meet with the local WordPress community. It was a great meetup. Kudos to the folks from Presslabs, Rainfall, Cosmoslabs, and Get Bowtied. Thanks for being so welcoming. I’ll come again!

I chose to talk about install.php, and how you could use it alongside mu-plugins and functionality plugins to speed things up when installing new WordPress sites. Here are my slides:

Get a headstart with install.php & Jetpack

You can also check the slides on GitHub.

Here is the full install.php I created for the purpose of this talk. Credit goes to Mike Schinkel and Kathy for a big part of the functions in there.

If you have questions about some of the Jetpack filters used in the talk, or if you would like to see more filters added to Jetpack, do not hesitate to join us on GitHub!

Myo: Control Plex without leaving your couch

Plex is awesome. It’s an important part of our media centre at home. When I started playing with Myo apps, I figured Plex should be my first stop. I set to develop a small desktop app that would allow me to navigate in Plex and play/pause movies from my couch.

Continue reading Myo: Control Plex without leaving your couch

Jetpack: add hashtags to the twitter sharing button

A few days ago I explained how to add hashtags to the tweets sent out by Jetpack Publicize. But what about the tweets your read can send using the Jetpack Sharing buttons at the bottom of your posts?

Here is how to get tags from your posts, and add them as hashtags to the twitter sharing button. As always, you’ll want to paste that code in a functionality plugin.

function jeherve_custom_sharing_title() {
        $post = get_post();
        if ( empty( $post ) ) {
                return;
        } else {
                // Create sharing title
                $sharing_title = get_the_title( $post->ID );

                // Get the tags
                $post_tags = get_the_tags( $post->ID );
                if ( ! empty( $post_tags ) ) {
                        // Create list of tags with hashtags in front of them
                        $hash_tags = '';
                        foreach( $post_tags as $tag ) {
                                $hash_tags .= ' #' . $tag->name;
                        }
                        // Add tags to the title
                        $sharing_title .= $hash_tags;
                }

                return $sharing_title;
        }
}
add_filter( 'sharing_title', 'jeherve_custom_sharing_title', 10, 3 );

Hat tip to Ryan for the idea!

Jetpack: add hashtags to tweets sent by Publicize

Jetpack’s Publicize module allows you to automatically publish your posts to your favorite Social Networks like Twitter or Facebook.

You can customize the message that is posted to Social Networks thanks to the small input field right above the Publish button:

Publicize Options

But what if you wanted to automatically add details to each Publicized post? Since both Twitter and Facebook support hashtags, you could append the post tags after the post title, like so:

Tweet tags

To do so, add the following code to a functionality plugin:

function jeherve_publicize_hashtags() {
	$post = get_post();
	if ( ! empty( $post ) ) {

		// Grab the tags of the post
		$post_tags = get_the_tags( $post->ID );

		// Append tags to custom message
		if ( ! empty( $post_tags ) ) {

			// Create list of tags with hashtags in front of them
			$hash_tags = '';
			foreach( $post_tags as $tag ) {
				$hash_tags .= ' #' . $tag->name;
			}

			// Create our custom message
			$custom_message = get_the_title() . ' ' . $hash_tags;
			update_post_meta( $post->ID, '_wpas_mess', $custom_message );
		}
	}
}

// Save that message
function jeherve_cust_pub_message_save() {
	add_action( 'save_post', 'jeherve_publicize_hashtags' );
}
add_action( 'publish_post', 'jeherve_cust_pub_message_save' );