PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 26, 2022

[FIXED] How to noindex Custom post tag in WordPress?

 August 26, 2022     javascript, php, wordpress     No comments   

Issue

I have a site which is displaying post tag in different format rather than the WP default tag format

WP default post tag url:

abc.com/tag/item

Where i have my tags in my website is like that

abc.com/post_tag/item

Tags in my site

https://readnational.com/post_tag/barbary-lion/

It display post_tag instead of tag

So i don't see the noindex option for this custom post tag in the yoast or rank math to noindex them all,

Kindly help me to add piece of code in function.php to noindex all tag links of my site

https://readnational.com/post_tag/barbary-lion/ https://readnational.com/post_tag/cow/

So for all tags

I hope someone would help me thanks


Solution

In robots.txt add:

User-agent: *
Disallow: /post_tag

Alternative in your functions.php:

function no_index_cpt()
{   $taxonomy = get_queried_object()->term_id;
    if ($taxonomy  === 'post-tag') {
        print '<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">';
    }
}

add_action('wp_head', 'no_index_cpt');


Answered By - hhh
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing