0

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.

3
  • 1
    So, where's the problem? Commented Jan 12, 2016 at 7:43
  • I want to add the meta description and meta keywords of the each for better search results of the webpage without using any SEO Plungins.For giving the unique description and keywords,title of each page. in my code it is adding the title of the page but i also want description and keywords of each page. Is there any solution to achieve this? Commented Jan 12, 2016 at 7:50
  • you can use is_page( 'Page_ID' ) as condition state to to this Commented Jan 12, 2016 at 8:18

2 Answers 2

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');
Sign up to request clarification or add additional context in comments.

Comments

0

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.