WordPress has a built-in featured called “sticky posts.” This puts select content above all others on your website. But what if you want to show the the latest sticky posts only? That’s when you have to make a few modifications to WordPress.
Unfortunately, this means you’ll have to add some code to the core files of WordPress. If you don’t feel comfortable making these edits, you can always spend time looking for a plugin to show the latest sticky posts for you.
However, I was unable to find one that fit my purposes.
In this tutorial, I’ll show you how to make WordPress show the latest sticky posts while using a shortcode. It’s not a difficult process, and I’ll even give you the code to paste into your website.
How to Use Sticky Posts
When you create a new post, you have the option to set it to be “sticky.” This tells WordPress that you prioritize the content and want it to appear first in lists.
You can set this option in the Visibility setting of a post. This option is not available for pages.
One thing you have to keep in mind, though, is that sticky posts are not supported by every theme. However, it’s not very common for a theme to disable this feature.
You can also use plugins to manage your sticky posts which usually have more features than what WordPress offers.
Inputting the Code
Before you make changes to your site, I suggest setting up a child theme. This will protect your site by saving your edits and modifications if your theme is updated. Otherwise, you could lose all of your adjustments and have to enter them in again.
There are some pros and cons to using a child theme, but usually the benefits outweigh the drawbacks.
Today, we’re going to edit the functions.php file of your theme. You can access these files by using FTP programs like FileZilla or File Manager in cPanel.
To keep things quick and easy, I’m just going to use File Manager.
Go to the root directory of your site and open the “themes” folder.
Open your theme’s folder.
Select the functions.php file and click, “Edit.”
Paste this code into the file:
This creates a new shortcode for us to use called, “[latest_stickies].” It uses the wp-query command to show sticky posts first.
As you can see, I placed the code under the “}” below the if statement for the theme version.
Save your changes to the file.
Placing the Shortcode
To show your latest sticky posts, go to any post or page on your site. You can create a new one if you’d like.
Paste the shortcode we just created form the code.
Update or save your post or page.
Now, your sticky posts will show in a list according to the latest published date.
Can you make the shortcode anything you like?
Yes. In the example above, we called it “latest_stickies.” However you can change this to anything else as long as you edit it in the code. However, I suggest leaving it as-is because it’s an obvious name and easy to remember its purpose. But, it’s up to you.
Will this shortcode work in a text widget for the sidebar?
Yes. Bear in mind that your theme may not allow sticky posts. However, it’s not very common for a theme to do this.
What are some good ways to show the latest sticky posts in WordPress?
In my example above, I used a specific landing page for sticky posts. I can then add this page to the navigation bar and label it something like, “Must See Posts” or something similar.
You can also paste this shortcode under a recent posts that isn’t sticky. This will give visitors something to click at the end of the content if you want them to see important articles.
You’re only limited by your imagination and design ideas, and shortcodes are usable throughout most areas of WordPress including most custom post types created by other plugins.
Engage Your Visitors
Showing the latest sticky posts in WordPress is another way to engage your visitor. It gives them a way to see content you deem to be important, which they may not know is available on your site. It’s all about making your content easier to find, and this method gets your articles in front of more eyes.
What kind of methods do you use to engage your audience? How often do you make a post “sticky?”
Author: Michael Brockbank
Michael has been in the tech industry in some form or another since the late 1990s. He’s built a variety of websites using HTML, Joomla and WordPress. Starting his freelance writing career in 2012, he’s completed thousands of projects world-wide covering a wide scope of topics. Michael is currently the Content Marketing Team Lead. Today, he manages a team of writers to create tutorials, blog posts and support content for customers. Outside of GreenGeeks, he manages a YouTube channel that helps others learn how to become freelance writers, bloggers and overall professionals.