Thursday, August 21, 2014

How to add SEO title for Categories in Wordpress

How to add SEO title for Categories in Wordpress

Open your functions.php file.Add the following lines.

File path: wp-content/themes/your-theme/functions.php

Store SEO titles in array with Category ID.

Function

$pagetitels = array(
            13 => 'Your Category Custom title', //Category ID and custom title
            18 => 'Your Category Custom title',
            17=> 'Your Category Custom title'
        );

Create function to overwrite default titles.

Function

function change_cptitle() {
    global $pagetitels;
    $catid = get_query_var('cat'); //Get Category ID
    if (array_key_exists($catid, $pagetitels)) {
        $title = $pagetitels[$catid]; // use a custom title
    } else {
        $title = get_the_category_by_ID($catid); // use the category name as title
    }
    return $title;
    }

Full Code

$pagetitels = array(
            13 => 'Chennai Real Estate Guide 2014| Chennai Property magazine ',
            18 => 'Luxury Living | Luxury Real Estate Magazine',
            17=> 'Architectural magazine | Architecture design ideas '
        );
        function change_cptitle() {
    global $pagetitels;
    $catid = get_query_var('cat'); //Get Category ID
    if (array_key_exists($catid, $pagetitels)) {
        $title = $pagetitels[$catid]; // use a custom title
    } else {
        $title = get_the_category_by_ID($catid); // use the category name as title
    }
    return $title;
    }
add_filter("single_cat_title", "change_cptitle");

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

No comments:

Post a Comment