简体   繁体   中英

how to add seperate meta tags for each page using header.php page on wordpress

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM