DIY SEO:
1: In the post/page editor for a page or post: Add custom field(s) (meta data) with required value(s) for your SEO meta tag(s).
- e.g. Open say your "Terms &Conditions" page in the page editor and
add a custom field "
my_noindex
" with a value of "y".
- N.B. if the custom field box is not visible below the editor, click
the "display options" drop-down at the top of the page and then the
"custom fields" check box that appears.
2: In functions.php (or better still in your own theme independent site_functions plugin): Add your SEO function (to be "called" by wp_head) which take these values for the current page and inserts them in the HTML <head>
.
// echo noindex tag if post or page has a "my_noindex" custom field with a value of "y"|"Y"|"yes" ...
function my_meta_tags() {
$noindex = (get_post_meta( get_queried_object_id(), 'my_noindex', true ));
if (strtolower(substr($noindex,0,1)) == 'y') {
?><meta name="robots" content="noindex" />
<?php return; // noindex so no point in doing any other SEO stuff
}
// other SEO stuff
}
add_action( 'wp_head', 'my_meta_tags',2);
Jeff Starr's article on rolling your own SEO code (including title and description) will help. It requires a custom/child theme as its code goes in header.php, however much of the code could be modified for the my_meta_tags function above. It may not apply SEO the way you want but that's the beauty of DIY: if you want to use your carefully crafted description in custom field (if present), else your custom excerpt, else first n chars of description; then you can write your code accordingly. I've also been intending to write an article on this subject - if I get round to it I'll add a link.
Omissions from article's code:
Prevent duplicate title tags (as some themes insert their own). Modern,
properly designed themes should enable you to remove the themes title tag
when you add the following to your site functions.php.
function my_remove_stuff() {
remove_theme_support( 'title-tag' );
}
add_action('after_setup_theme', 'my_remove_stuff', 15);
Canonical Tags. Add the following to the first function above:
//if post or page has a "my_canon" custom field
$my_canon = get_post_meta( get_queried_object_id(), 'my_canon', true );
if ( ! empty($my_canon)) :
echo '<link rel="canonical" href="' . $my_canon . '" />';
remove_action('wp_head', 'rel_canonical'); // prevnts Wordpress inserting a canon tag - we don't want two
endif;
An SEO plugin is the right option for many users. However if you are happy writing your own code there are many benefits:
avoid bloat, avoid lock-in/dependence on plugin, avoid (in some cases) paying for support, SEO works the way you want it; no SEO conflict issues with SEO on your own dynamic custom pages etc.