Support » Fixing WordPress » Category name in page title – Google Analytics content grouping

  • Hello,

    Google has launched a new Content Grouping feature. There is just one issue with that.

    URLs on my blog are structured in the following way: http://www.mydomain.eu/post-name. I do not want to add category name to the URL as it would impact its robot-friendliness.

    Fortunately, GA also allows to group content by page title. So if I can put the names of the categories into the <title></title> tag, I still can create the content group.

    Now how does that work? Is there a way to add category into the <title></title> without having to input it manually to every single post?

    I run a couple of sites. Is there a way of universally fixing this for all of them? I know an All-in-One SEO plug-in would solve this but I don’t like to install additional plug-ins unless I really have to.

    Cheers for ideas!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi

    Add the following codes in your website’s activated Theme header.php file.

    <title>
    	<?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' –'; } ?>
    <?php if(is_single()) { $cats = get_the_category($post->ID);
    foreach( $cats as $cat ) { echo $cat->cat_name; echo ' - '; }
    } ?>
    	<?php bloginfo('name'); ?>
    </title>

    Reference: Function Reference/get the category

    Thank you so much, Mrinal! It works!

    Just a question, if I wanted to add two categories into the title, would that be possible? My posts are very rarely only in one category.

    Thank you for your advice!

    Hi,

    I’ve checked the following snippet & worked for me with Twenty Twelve Theme. You can check also, I just call all the categories instead of a single category.

    <title>
    	<?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' –'; } ?>
    <?php if(is_single()) { $cats = get_categories($cat_args);
    foreach( $cats as $cat ) { echo $cat->cat_name; echo ' - '; }
    } ?>
    	<?php bloginfo('name'); ?>
    </title>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category name in page title – Google Analytics content grouping’ is closed to new replies.