Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code to add to your functions.php to only display Sticky posts on your main blog page
<?php
// add the following code to your functions.php file
add_action( 'pre_get_posts', 'fe_pre_get_posts_sticky_only' );
function fe_pre_get_posts_sticky_only( $query ) {
if (
$query->is_main_query()
&& $query->is_home()
) {
$query->set( 'post__in', get_option('sticky_posts') );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment