- This topic has 42 replies, 3 voices, and was last updated 3 years, 3 months ago by
Fernando.
-
AuthorPosts
-
February 1, 2023 at 1:58 am #2516717
Jodie
I’ve now added the add-nofollow to the class list of the Headline Block in the Content Template element for displaying posts on archive pages.
When I look at the page source of one of the category pages, one post that’s not supposed to have a “nofollow” attribute does have one.
When I go into the back end of that post, and check the post meta that determines whether the “nofollow” attribute gets added, it’s unticked, as it should be.
Do you know why this might be happening?
Thank you so much for your help with this!
February 1, 2023 at 5:46 pm #2517772Fernando Customer Support
Where did you add the Snippet here?: https://generatepress.com/forums/topic/how-to-change-links-on-archive-pages-from-dofollow-to-nofollow/#post-2515041
February 1, 2023 at 7:57 pm #2517834Jodie
Hi Fernando
I’ve taken some screenshots of what is happening when I add the snippet. It is attributing nofollow to a post that I definitely don’t want to be nofollow so I took it out since we were last in touch. I’ve added it in again for the purpose of showing you what is happening.
I’ve given lots of detail below.
Thanks so much.
Cheers Jodie
February 1, 2023 at 8:04 pm #2517840Fernando Customer Support
Can you enable
default valuein the custom post meta settings?If that doesn’t work, do you have a staging site for testing?
February 1, 2023 at 8:19 pm #2517850Jodie
I’ve enabled the default value in the custom post meta settings.
I will clear the cache on all caching plugins and Cloudflare and see what happens.
Yes, I can set up a staging site for testing.
Thanks so much for your prompt response.
I’ll let you know what happens
Cheers Jodie
February 1, 2023 at 8:24 pm #2517854Fernando Customer Support
Alright!
February 1, 2023 at 8:32 pm #2517858Jodie
Sadly Fernando enabling the default value in the custom post meta settings hasn’t fixed the issue.
February 1, 2023 at 8:37 pm #2517860Fernando Customer Support
Can you set up a staging site? Let’s check what value you post meta is returning.
February 1, 2023 at 8:52 pm #2517864Jodie
Okay shall do re staging site and then I will let you know.
I will remove the script from my live site for now.
Thanks so much Fernando.February 1, 2023 at 8:58 pm #2517867Fernando Customer Support
Alright! You’re welcome!
February 1, 2023 at 9:33 pm #2517889Jodie
Hi Fernando
I’ve created the staging site and added the script.
I’ve sent you the credentials below.
Cheers Jodie
February 1, 2023 at 10:09 pm #2517910Fernando Customer Support
After this line:
$boolnofollow = get_post_meta(get_the_ID(), 'add_no_follow');Add this:
var_dump($boolnofollow);Give these two posts different values for add_no_follow:
Chiaogoo Vs Hiyahiya Knitting Needles Reviewed 11 Best Interchangeable Knitting Needles [Recommended 2023]February 1, 2023 at 10:16 pm #2517917Jodie
Thanks so much Fernando
In the staging site I’ve added this var_dump($boolnofollow); to the Theme Functions PHP File
I don’t know what to do when you say “Give these two posts different values for add_no_follow” what do I need to do please?
February 1, 2023 at 10:21 pm #2517919Jodie
Sorry here’s something else weird that I’m seeing on the staging site archive pages
February 1, 2023 at 10:23 pm #2517920Fernando Customer Support
It’s okay, I’ve got it.
Try this instead:
add_filter( 'render_block', function( $block_content, $block ) { if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'add-nofollow' ) !== false ) { $boolnofollow = get_post_meta(get_the_ID(), 'add_no_follow'); if($boolnofollow[0]){ $myreplace = 'href'; $myinsert = 'rel="nofollow" href'; $block_content= str_replace( $myreplace, $myinsert , $block_content ); } } return $block_content; }, 10, 2 );Let us know how it goes.
-
AuthorPosts
- You must be logged in to reply to this topic.