4 Ways to Maximize Sticky Posts Feature in WordPress

HomeWordPress4 Ways to Maximize Sticky Posts Feature in WordPress

4 Ways to Maximize Sticky Posts Feature in WordPress

In WordPress, when you publish a new article it will be put at the top of the home page. If you create another ones, your previous articles will be shifted to the lower side.

For a specific reason you may want to feature a prominent article of your blog and keep it at the top of your home page. WordPress is actually has a built-in feature to cover this but not everyone know about it.

Unfortunately, the sticky posts feature in WordPress is very limited. You can only have one sticky post to be displayed only at the home page, nowhere else. What if you want to add a sticky post on a category?. We’ve covered this in the previous post. Go for if to find out how.

In this article we are going to discus how to maximize sticky posts feature in WordPress with some simple ways.

1. Set auto expiry

Sticky post is not something you need to display all the time. You only need to display a sticky post for a period, may a week or month. You don’t need to re-edit your post and uncheck the sticky option every time you want to take down a sticky post. There is a clever way to end up a sticky post period.

Simply install the Expire Sticky Posts plugin to set an automated expiry of your sticky post. This plugin has not been updated for more than two years but it still works well.

2. Display a sticky post in category

If you run a complex blog with several categories, chance that you want to display a featured post on each category. Since the default sticky posts in WordPress only allows you display sticky post at the home page, you can do an advanced way to display sticky posts in category. As I mentioned, we have written an article on how to display sticky post in the WordPress category. Simply visit here to read.

3. Display the sticky posts you’ve created

If you frequently create a sticky post, then you would have a collection of sticky posts. You can display them to allow your readers track which are the prominent articles on your blog. Go to your theme’s function.php file and add the following code.

function wpb_latest_sticky() { 

/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );

/* Sort the stickies with the newest ones at the top */
rsort( $sticky );

/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 5 );

/* Query sticky posts */
$the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
// The Loop
if ( $the_query->have_posts() ) {
  $return .= '<ul>';
  while ( $the_query->have_posts() ) {
    $the_query->the_post();
    $return .= '<li><a href="' .get_permalink(). '" title="'  . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>';
    
  }
  $return .= '</ul>';
  
} else {
  // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

return $return; 

} 
add_shortcode('latest_stickies', 'wpb_latest_sticky');

After adding the code, create a new page to display sticky posts. Add the following shortcode on the page.

[latest_stickies]

4. Set a sticky post for custom post type

Sticky post can only be set for WordPress’s default post type. If you want set a custom post type as a sticky post, you need to install an additional plugin called Sticky Custom Post Types. This plugin is also has not been update for more than two years but still can be used without any problem.

Once you have installed and activated the plugin, go to Settings –> Reading and enable sticky posts for any post type you want.

This page may contain affiliate links, which help support bettertechtips.com. Learn more

hand-picked weekly content in your inbox

.

related posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here