Skip to content

Instantly share code, notes, and snippets.

@salcode
Last active January 2, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salcode/8302846 to your computer and use it in GitHub Desktop.
Save salcode/8302846 to your computer and use it in GitHub Desktop.
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