Sticky posts in WordPress are a powerful feature for highlighting your most important content, like featured articles on a blog or magazine site. When enabled, they appear at the top of your post listings—but only if your theme supports them. In this intermediate tutorial, we'll show you how to reliably display the latest sticky posts anywhere on your site using a custom shortcode. As WordPress experts with years of theme customization experience, we've tested this on numerous sites to ensure it works flawlessly.

Note: This guide assumes basic knowledge of HTML/CSS and WordPress themes.
Subscribe to WPBeginner for step-by-step video tutorials. Prefer reading? Continue below for detailed instructions.
Add this proven code snippet to your theme's functions.php file or a site-specific plugin:
function wpb_latest_sticky() {
// Get all sticky posts
$sticky = get_option('sticky_posts');
// Sort stickies with newest on top
rsort($sticky);
// Get the 5 newest stickies (change 5 as needed)
$sticky = array_slice($sticky, 0, 5);
// Query sticky posts
$the_query = new WP_Query(array(
'post__in' => $sticky,
'ignore_sticky_posts' => 1
));
// Initialize return variable
$return = '';
// The Loop
if ($the_query->have_posts()) {
$return .= '<ul>';
while ($the_query->have_posts()) {
$the_query->the_post();
$return .= '<li>' . get_the_title() . '<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');This code queries your WordPress database for the top 5 newest sticky posts (adjustable), formats them as a clickable list with titles and excerpts, and registers a shortcode [latest_stickies] for easy use.
Simply insert [latest_stickies] into any post, page, or text widget to display them instantly.
To enable shortcodes in text widgets, add this line to your functions.php:
add_filter('widget_text', 'do_shortcode');Ideal for custom homepages, featured sliders, or magazine layouts, this snippet elevates your site's user experience. For more advanced control, check our tutorial on adding expiration dates to sticky posts.
Thanks for reading! Subscribe to our WordPress YouTube channel, follow us on Twitter, and join us on Google+ for more pro tips.