Conditionally disable Jetpack’s Infinite Scroll

So you implemented Jetpack’s Infinite Scroll feature in your theme, but you don’t want it in a particular page, say a category archive page. Here’s the code you need to add to your theme’s functions.php file:

 * Disable Jetpack's Infinite Scroll Conditionally
function _kucrut_disable_jetpack_infinite_scroll_conditionally() {
	if ( true === my_conditionals() ) {
		remove_theme_support( 'infinite-scroll' );
add_action( 'template_redirect', '_kucrut_disable_jetpack_infinite_scroll_conditionally', 9 );

Just remember to change my_conditionals() with your actual conditionals and to never add the action callback after priority 9, otherwise it will be too late 😉

Add HTML Tags in Post and Widget Titles

In a recent project, I needed to use <span /> tags to add some styles (just color, actually) to post and widget titles. By default — and there’s no hook to disable this — WordPress strips any HTML tags found in post and widget titles. Here’s my solution to this problem. Please keep in mind that I only needed to add <span /> tags, so if you need to add more tags, you should modify the code to fit your needs :) Continue reading Add HTML Tags in Post and Widget Titles

Remove Protected Post Title Prefix

By default, WordPress will prefix protected post’s title with Protected. This is good when the password hasn’t been supplied. Unfortunately, it doesn’t remove this prefix when the correct password has been supplied which is not good IMO. Here’s a snippet to ‘fix’ this behavior:
Continue reading Remove Protected Post Title Prefix

Insert Image with Custom Size into Post

Since version 2.9, WordPress provided a new function, add_image_size() to define additional image sizes along with the three default sizes: Thumbnail, Medium and Large. After defining the additional sizes, we can use them in our themes either using the_post_thumbnail(), wp_get_attachment_image(), or any other functions that suit your needs.
Continue reading Insert Image with Custom Size into Post

Unique post category/term

In WordPress, we can set multiple categories/terms for a post. This is true for both hierarchical taxonomies (ex: category) and non-hierarchical taxonomies (ex: post_tag). However, on a project I’ve worked on, the client wanted me to make the category metabox to use radio inputs (exactly like WordPress’ new post format feature) instead of checkboxes to prevent the editor from setting multiple categories for the post (s)he writes. This request forced me :) to come up with a solution. I was also inspired by Justin Tadlock’s idea on using a taxonomy for theme layout. Here’s my solution in hope it could be useful for others.
Continue reading Unique post category/term

Add Custom Attributes to WordPress’ Posts Navigation

The Problem

We need to add our custom class(es) to the posts navigation links to be able to add some styles.

The Solution

Use the available next_posts_link_attributes and previous_posts_link_attributes hooks.


Open your theme’s function.php file and add these lines (must be inside the <?php ?> tag):

add_filter( 'next_posts_link_attributes', 'kc_next_post_link_attr' );
add_filter( 'previous_posts_link_attributes', 'kc_prev_post_link_attr' );

function kc_next_post_link_attr() {
	return 'class="next-page"';

function kc_prev_post_link_attr() {
	return 'class="prev-page"';