- This topic has 12 replies, 4 voices, and was last updated 3 years, 11 months ago by
David.
-
AuthorPosts
-
March 2, 2022 at 11:04 am #2139859
Kelsey
Hi,
I’d like my posts to still be indexed and found, but I don’t want any links to those posts to appear on my site. I don’t want them to show up as new posts, etc. How can I accomplish this? Here’s one of the pages in question:
https://thegoldenlamb.com/how-to-run-an-seo-report-in-rankiq/
Since my blog is a recipe blog, I don’t want this software review blog post to show up to my normal audience.
Thanks,
March 2, 2022 at 11:16 am #2139878David
StaffCustomer SupportHi there,
if you want to exclude specific posts from the main query then you can:
1. Create a category term that you will use to exclude the posts eg.
no-show
Edit that category term and get its ID from the Browser URL Field, you will need this.
2. Assign all the posts you want hidden from the feed with the no-show term
3. Add this PHP Snippet:add_action('pre_get_posts', 'exclude_category_posts'); function exclude_category_posts( $query ) { if($query->is_main_query() && !is_admin()) { $query->set('cat', array( -22 )); } }In this part of the code:
$query->set('cat', array( -22 ));You need to change the
-22to minus your term ID – so if theID=66then the line will be:$query->set('cat', array( -66 ));This will exclude those posts from the main query.
What Google will make of this, i have no idea 🙂
March 2, 2022 at 11:41 am #2139909Kelsey
Thanks, David. Where do I place the final PHP code? In my functions.php file? Would want to include it a child version, no?
March 2, 2022 at 3:42 pm #2140077Ying
StaffCustomer SupportHi Kelsey,
You can add the PHP code using one of the method it introduced:
https://docs.generatepress.com/article/adding-php/Please make sure you have a child theme installed if you want to add it to functions.php file.
https://docs.generatepress.com/article/using-child-theme/March 2, 2022 at 8:53 pm #2140253Kelsey
Thanks Ying,
Is there a way to make this work on Mobile? Your fix works on desktop but I need it to also work on mobile.
Thanks,
Kelsey
March 2, 2022 at 10:32 pm #2140323Fernando Customer Support
Hi Kelsey,
The Post “How to Run an SEO Report in RankIQ” still appears on my end on both Desktop and mobile.
Moreover, the code provided by David should work on any view/device. Can you confirm if you’ve added the correct Category ID?
Kindly see: https://share.getcloudapp.com/6quZKD4D
Hope to hear from you soon. 🙂
March 3, 2022 at 6:20 am #2140726Kelsey
Hi there,
I added this code:
add_action(‘pre_get_posts’, ‘exclude_category_posts’);
function exclude_category_posts( $query ) {
if($query->is_main_query() && !is_admin()) {
$query->set(‘cat’, array( -403 ));
}
}with my post ID. I used a snippets plugin to add it. I would add it to my functions.php file but I don’t seem to have a child theme for GeneratePress? I add all my custom CSS within the “customize” function on my dashboard rather than editing my actual CSS file.
Do I literally just paste the above code at the end of my functions.php file? I don’t want to break my site, lol. I did once before, years ago, when adding code to functions.php so I’m a bit frightened about doing it again.
March 3, 2022 at 6:27 am #2140734Kelsey
Not post ID, category ID. That was a typo.
March 3, 2022 at 6:36 am #2140739David
StaffCustomer SupportIf you don’t have a child theme then you need to install the Code Snippets plugin:
https://en-ca.wordpress.org/plugins/code-snippets/
Add a new Snippet and paste that code in.
The code is device agnostic – you may just need to clear any server/plugin/browser caches to see the change on your mobile. If the issue persists connect to a different network and test
March 3, 2022 at 7:20 am #2140787Kelsey
Hi David,
Thank you. I tried it again. I think it worked. Can you check on your end?
https://thegoldenlamb.com/how-to-run-an-seo-report-in-rankiq/
Thank you
March 3, 2022 at 7:49 am #2140912David
StaffCustomer SupportThat post displays correctly, and i cannot find it in the main loop 🙂 All good to me.
March 3, 2022 at 7:54 am #2141000Kelsey
Great. Thank you.
March 3, 2022 at 8:04 am #2141017David
StaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.