Site logo

Archived topic

HIde a single post ID from 'Recent Posts' widget

3 replies · Started by Lisa on March 11, 2021

Viewing posts 1–4 of 4

I have a single post that I dont want showing up in 'Recent Posts' widget
as this post should only be accessible via an offsite link.
https://prnt.sc/10iswqv

I found this as a possible solution which I added to Elements > Hooks > but it does not work
https://prnt.sc/10iszcc

function exclude_single_posts_home($query) {
if ($query->is_home() && $query->is_main_query() && !is_admin()) {
$query->set('post__not_in', array(16461));
}
}

add_action('pre_get_posts', 'exclude_single_posts_home');

any suggestions

this post sits within its own category ID 1

I resolved by removing recent posts entirely from the side bar
no need to answer
Thanks

Glad to hear that!

This archived topic is closed to new replies.