Sticky posts acts as featured posts that sticks at the top of all posts no matter when they have been published. Most themes these days have there own way of displaying featured posts. May it be in the form of a slider on the top or just a list widget in the sidebar. Normally most themes take care that if they have an option to display featured posts on the home page then they do remove the sticky posts from the homepage posts loop. But when I say most themes then it definitely does not mean all themes. So if your theme is showing sticky post and you want to get rid of them then just include the below code in the functions.php file of your theme–
Remove sticky posts from home page
add_action( 'pre_get_posts', 'xt_ignore_sticky' ); function xt_ignore_sticky( $query ) { if ($query->is_main_query() && $query->is_home()) { $query->set( 'ignore_sticky_posts', 1 ); } }
Remove sticky posts from everywhere
The above code will remove sticky posts from your homepage. If you would like to remove sticky posts from everywhere then add the below code–
add_action( 'pre_get_posts', 'xt_ignore_sticky' ); function xt_ignore_sticky( $query ) { if ($query->is_main_query()) { $query->set( 'ignore_sticky_posts', 1 ); } }
P.S. – Incorrectly modifying PHP code can break your site, so please be careful while doing so.
Do you like this article?