WordPress, as CMS, let’s you create sticky posts in your site as you need it, which always sticks at the top of the blog page created for your site. And is there any limit in creating sticky posts in your site? Well, there is no limit on it. And what if your site is displaying the post excerpt for almost all of the posts added in your site? Would you like to display the post content for the sticky posts added your site instead? Well, if you want to then, we are here describing about displaying full content for sticky posts added in your site. So, let’s move ahead and do the same, shall we?
What is sticky post in WordPress?
First of all, we might need to know about what is sticky post in WordPress. As we have stated earlier, it is the post created in your site, which always sticks at the top of the blog page created in your site. If some of the CSS is applied to it, then, it will probably stand out with other posts created in your site.
Also, there is no limitation on creating it in your site, which is also stated above. Also, it will only work for the blog pages, not the other archive pages created in your site out of the box. But with the help of some plugins, you may be able to do so for the archive pages too.
Sticky posts does not hamper the number of posts to be shown in the archive pages too, ie, blog page will display the sticky posts first and then the total number of posts set in blog pages to display. Also, it will be displayed later on on the post loop too.
How to create sticky post in WordPress?
In order to create sticky post in your site, you can create a new post or edit the previous post created in your site. Now, after that, you will see the Publish section in right corner at top. Under there, you can see Visibility option, click on it and you will fine: checkbox option. Just put the checkmark on it and publish/update the post. Now that post is sticky post in your site.
However, if you are still confused onto it, then maybe you can follow up this link for more details.
Now after knowing about how to create sticky post in your site, let move ahead about displaying full content for sticky posts added in your site, shall we?
Displaying full content for sticky posts in your site
After you have known about creating sticky posts in your site, let’s move ahead and learn on displaying full content of sticky posts for the blog page in your site.
First of all, you need to know about what function in WordPress can check for the sticky post in your site. Well, we have got you covered on the function name for same too. And it is
is_sticky() function. This function will help you to identify same. If the current post is sticky then, it will do its work else it will do nothing for same.
So, let’s move ahead and implement the post loop for blog pages in your site, shall we?
For this, open up your post loop file for displaying the blog posts listing for your blog page. Now, after opening up required file, find the function:
the_content() which displays the post excerpt and post content respectively. Now, after finding that code: change that in the following below way to display sticky post as full post content and later, only the post excerpt:
if ( is_sticky() ) :
// Displaying full content for the sticky post.
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'theme-textdomain' ),
'span' => array(
'class' => array(),
the_excerpt(); // Displaying excerpt for the archive pages.
Now, from above, as you can see we have added the condition check for sticky post via
is_sticky() function. So, from this check, if there is sticky post then, this check will display the post content for sticky post and for the other, the post excerpt.
Output of displaying full content for sticky posts in your site
Now, after applying the above PHP code as stated in same file, you can find similar result for your site too as below screenshot:
Here, in the above screenshot, you can see that the first post is standing out with others. It is displaying the post content and later posts, the excerpt of the posts. Also, due to the CSS addition for the sticky post too, it is standing out with other posts too.
You may also want to read:
- Creating Sticky Post In WordPress
- How To Filter WordPress Content
- How To Create Meta Box In WordPress
- Add And Display Featured Image In WordPress
- Display Image Caption Under Featured Images In WordPress
If you have successfully followed this tutorial and have became successfully able on displaying full content for sticky posts in blog page added in your site then, we can assume that you are now more familiar on this than before. But, if you are still confused about how to do it and want more help on this then do drop the comment below in the comment box and we will follow it up.