skip to Main Content

I want to add the separate meta tags for the each page using the header.php

To add the title,Meta Description,Meta Keywords of the every page
for better SEO Anlayis. I want achieve this through code on header.php page.

<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<!--<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />-->

<style>
/*.alignleft { left:0px !important;}
*/
</style>

<title>
<?php
    /*
     * Print the <title> tag based on what is being viewed.
     */
    global $page, $paged;
    wp_title( '|', true, 'right' );
    // Add the blog name.
    bloginfo( 'blogname' );
    // Add the blog description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) )
        echo " | $site_description";
    // Add a page number if necessary:
    if ( $paged >= 2 || $page >= 2 )
        echo ' | ' . sprintf( __( 'Page %s'), max( $paged, $page ) );
?>
</title>
</html>

Thanks in advance.

2

Answers


  1. The easy way is use a hook using condition.

    Simply use this code to your functions.php but change english is_page('english') to your page_ID or slug or title

    function add_meta_data_firefog() {
    
        if ( is_page('english') ) {
            echo'<meta name="Keywords" content="Keyword1,Keyword2,Keyword3,Keyword4,Keyword5,Keyword6">';
            echo'<meta name="Description" content="Your Description">';
        }
        if ( is_page('aboutus') ) {
            echo'<meta name="Keywords" content="Keyword1,Keyword2,Keyword3,Keyword4,Keyword5,Keyword6">';
            echo'<meta name="Description" content="Your Description">';
        }
        if ( is_page('newspaper') ) {
            echo'<meta name="Keywords" content="Keyword1,Keyword2,Keyword3,Keyword4,Keyword5,Keyword6">';
            echo'<meta name="Description" content="Your Description">';
        }
    }
    add_action('wp_head', 'add_meta_data_firefog');
    
    Login or Signup to reply.
  2. Hi can i do this with the nromal phpo website?
    function add_meta_data_firefog() {

    if ( is_page('english') ) {
        echo'<meta name="Keywords" content="Keyword1,Keyword2,Keyword3,Keyword4,Keyword5,Keyword6">';
        echo'<meta name="Description" content="Your Description">';
    }
    if ( is_page('aboutus') ) {
        echo'<meta name="Keywords" content="Keyword1,Keyword2,Keyword3,Keyword4,Keyword5,Keyword6">';
        echo'<meta name="Description" content="Your Description">';
    }
    if ( is_page('newspaper') ) {
        echo'<meta name="Keywords" content="Keyword1,Keyword2,Keyword3,Keyword4,Keyword5,Keyword6">';
        echo'<meta name="Description" content="Your Description">';
    }
    

    }
    add_action(‘wp_head’, ‘add_meta_data_firefog’);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search