Add tags to the section via functions.php

I’ve got a custom theme I’ve developed and it’s basically a 4 page brochure site for a client and I’ve managed to do away with a few plugins by building in custom-post-types, gzipping via .htaccess and minifying via gulp etc etc.

I’ll be keeping the security plugin on the site, but I’d like to remove Yoast, the only benefit it brings, bearing in mind how optimised the site is, is that it allows me to add the meta tags and snippets for each page for SEO purposes.

Is there a function that I can add add to my functions.php file that allows me to add <meta> tags to different pages via the page id?

When one Googles this subject all you get is plugin articles, or info about general wp meta.

Any help would be awesome.



The hook you’re looking for is specifically wp_head which could look something like this:

function theme_xyz_header_metadata() {

    // Post object if needed
    // global $post;

    // Page conditional if needed
    // if( is_page() ){}


    <meta name="abc" content="xyz" />


add_action( 'wp_head', 'theme_xyz_header_metadata' );

I believe in the long run though, since WordPress is so portable, Yoast SEO is probably the most reliable, flexible bet for SEO than something you would do yourself so I would advise against this personally.

Leave a Comment