I use wordpress and would like to add 2 lines of code to the header of one page only.
The problem is that header.php will change all the site’s headers and I want it to change only the header of one specific page.
The only thing I want to do is add this 1 line :
<META name="robots" content="noindex, nofollow"/>
If you want to have a different header for a certain page you need to download your header.php from FTP, rename it to header-new.php (replace “new” with whatever you want), re-upload header-new.php to the same directory as your original header.
– On the page template you want the new header to show up on
replace:
with
and now your new header will show up only on that specific page template
you have to just add your pageid on your header file like this
it will just display meta on specific page which you want.
Suppose you only want to output the code for the page with ID = 5, set
page_int
to5
. This is an integer, so do not use single quotes around it.Just correcting the answer of FDL, use this:
Custom Fields are a great way to allow you to have page specific meta data that you can create logic on in your template files. The Codex link gives great examples of this.
There’s a plugin to do exactly the thing requested.
HiFi (Head Injection, Foot Injection)
There’s a “This plugin hasn’t been updated in over 2 years….” notification, but I’ve just tested it on WP 3.5.2 – it works.
An easier, non-coding solution to changing the robots meta tag on a per-page basis is by using the Yoast SEO plugin.
https://yoast.com/wordpress/plugins/seo/
You can set individual pages (such as a form thank-you page) as noindex and even nofollow if you’re so inclined. If you’re using Yoast to generate your sitemap as well, then you can exclude that page from the sitemap at the same time you noindex it, which will prevent errors in Search Console.
If you want to have the ability to add some other tags or esoteric syntax to the then you can use the Per Page Add to Head plugin
https://wordpress.org/plugins/per-page-add-to/
Which will allow you to be very granular about which page gets which code.
This worked for me. I didn’t feel I needed to get the post type. I just needed the ID.
This did not work for me as spec’d in the Codex (https://developer.wordpress.org/reference/functions/is_page/).
is_page( 1234 )
Try with this:
You can check the reference here: https://developer.wordpress.org/reference/functions/is_page/
this code will put meta only for home page, you may use is_single, is_archive, is_404 etc.