WordPress has this very cool function referred to as sticky posts. Consider sticky posts as featured posts in your weblog. Once you mark a put up as sticky, it reveals up above your new posts, however provided that your theme permits it. On this tutorial we are going to present you methods to show the newest sticky posts in WordPress.
Observe: That is an intermediate stage tutorial and requires fundamental HTML / CSS information + WordPress themes information.
Video Tutorial
For those who don’t just like the video or want extra directions, then proceed studying.
Very first thing it's essential to do is copy and paste this code snippet in your theme’s functions.php file or in a site-specific plugin.
operate wpb_latest_sticky() add_shortcode('latest_stickies', 'wpb_latest_sticky');
The code above queries the WordPress database to retrieve the 5 newest sticky posts. It then shows every sticky put up’s title with a hyperlink in a listing format. Now we have wrapped all that in a operate and created a shortcode.
Now to show your newest sticky posts, you should utilize the shortcode [latest_stickies] in any WordPress put up, web page, or perhaps a textual content widget.
If you need to make use of shortcodes inside a textual content widget, then you'll need so as to add this additional line of code in your theme’s capabilities.php or site-specific plugin.
add_filter('widget_text', 'do_shortcode');
This snippet and performance can very effectively be utilized in featured slider, or some other superior function that you just wish to show in your website. This snippet is generally geared towards a WordPress website that has a custom homepage or model look.
That’s all, we hope this text helped you show newest sticky posts in your WordPress weblog. You might also need to checkout our tutorial on methods to add an expiration date to sticky posts in WordPress.
For those who appreciated this text, then please subscribe to our YouTube Channel for WordPress video tutorials. You may as well discover us on Twitter and Google+.