简体   繁体   中英

Excluding posts with certain tag from blogpage

I have succeeded in excluding certain categories from my blogpage by editing the function.php, however i cannot seem to exclude all posts with tag id 113 from my blog. Can anyone help me out by pointing out which code i should use? Thanks in advance, Best regards,

you can use the code:

if(!has_tag(113))
{
  //Display your posts
}

The above code should be used inside the Wordpress loop.

==> In order to filter your posts inside functions.php you can use " pre_get_posts " hook:

function exclude_tag($query)
{
    if ($query->is_main_query()) {
        $query->set('tag__not_in', array( '113' ));
    }
}
add_action('pre_get_posts', 'exclude_tag');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM