Last Updated: February 25, 2016
·
944
· saif_cse

SEO meta techniques for a wordpress blog

SEO became the important part of websites. Wordpress comes with the great concept of blog, CMS and with nice SEO support. Although I'm sharing here the some techniques for basic meta for different pages in wordpress to be handled in a common header section upon your page type, content. Here goes my thoughts...

Basically 3 most common part/page used in a wordpress blog/site, where we goes for visit are

single.php for single post
category.php for any type category/term
index.php for blog home/default template for other types

At first we have common meta tags which will be used if not a single post or category page requested. For category page, we taken category title as a meta keyword and titles of posts under the category as a meta description. For single post page, post title as as meta description and post tags are as meta keywords. Finally a common meta key/description for index/home or other requested page. Here goes the code snippet:

<?php
if(is_category()){
    $cat = get_query_var('cat');
    $cmeta_desc = '';
    $cposts = get_posts(array('numberposts' => -1, 'post_type' => 'post', 'category' => $cat));
    if($cposts){
        foreach ($cposts as $ck => $cp) {
            $cmeta_desc .= $cp->post_title.",";
        }
    }
    $cmeta_desc = rtrim($cmeta_desc, ",");
    ?>
    <meta name="description" content="<?php echo $cmeta_desc;?>">
    <meta name="keywords" content="<?php single_cat_title();?>">
<?php
} else if(is_single()) {
    $tags = '';
    $tag_list = wp_get_post_tags($post->ID);
    foreach ($tag_list as $tk => $tag) {
        $tags .= $tag->name.",";
    }
    $tags = rtrim($tags, ",");
?>
    <meta name="description" content="<?php echo $post->post_title;?>">
    <meta name="keywords" content="<?php echo $tags;?>">    
<?php
} else {
?>
    <meta name="description" content="PHP developer, tech savvy, tech blogger, freelancer">
    <meta name="keywords" content="php, mysql, wordpress, codeigniter, web developer, freelancer, web consultant">  
<?php
}
?>

Hope this will give you guys some idea as well as some help in wordpress.

Happy blogging!