Show category in the browser title

pending (8 posts) (3 voices)

  1. Victorross
    Member

    I want to show the category from the post in the title of the browser, i know i have to edit header.php line 6, it looks like this:

    <title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title>

    I dont know how to put the category name, i try with

    <?php the_category(', ') ?>

    But it show the

    <a href="........">.........</a>

    Remember i only choose ONE category per each post, so it is not difficult to show the name.
    Wait for replay!

    Posted 1 year ago #
  2. Elliott
    Support

    Hello Victorross,

    See here, http://codex.wordpress.org/Function_Reference/wp_title,

    You can try using single_cat_title() but I am not sure if it will work for you as I think it needs to be used inside a loop. You could also try using this, http://codex.wordpress.org/Function_Reference/get_the_category, and set an ID right before like this,

    <?php the_post; get_the_category(); $category = get_the_category($post->ID); echo $category[0]->cat_name;?>

    Though I'm not sure if that will work for you either. Anyways, this is bordering custom work so if you are having trouble then it would be best to hire a freelancer to get this taken care of for you Victorross.

    Posted 1 year ago #
  3. Victorross
    Member

    Hi Elliott! Thanks for the replay, great support!
    Now i want to ask you something else, i use the second options and it works, if you look at http://www.portalcorrientes.com/2011/02/05/sabado-5-10/
    The title is "Mizza - Sabado 5 < Portal Corrientes"
    Where "Mizza" is the category, "Sabado 5 < Portal Corrientes" the post title and web name.
    But when i go to the ARCHIVES, for example:
    http://www.portalcorrientes.com/category/categorias/restaurantes/mizza/
    The title is "Mizza - Mizza < Portal Corrientes"
    Is there any way to clean the TITLE for the arcivhe.php, i mean, where do the <?php wp_title('«', true, 'right'); ?> take from the second "Mizza" (the category name) so i would like to leave the

    <?php the_post; get_the_category(); $category = get_the_category($post->ID); echo $category[0]->cat_name;?>

    And then if you go to the archives pages the <?php wp_title('«', true, 'right'); ?> only shows the web name.
    By this way i will be eliminating the archives title, and let only for the archives the web name as title.

    I hope you can understand me.
    Please look at all my posts in the forum and consider that most of them i have get the solution by my self and of course share it with all the users!
    Thanks a lot!

    Posted 1 year ago #
  4. Elliott
    Support

    You can try placing a wp_reset_query(); right before the_post; but you will probably have to resort to checking if the page is an archive page like so,

    <?php if (is_archive()) { archive title code } else { regular title code } ?>

    Posted 1 year ago #
  5. Victorross
    Member

    Hi Elliott! I put this code:

    <?php if (is_archive()) {?>
    <?php wp_title('&laquo;', true, 'right'); bloginfo('name'); ?>
    <?php } else {?>
    <?php wp_reset_query(); the_post; get_the_category(); $category = get_the_category($post->ID); echo $category[0]->cat_name; wp_title('&laquo;', true, 'right'); bloginfo('name');}?>

    But for some reason i get the CATEGORY name in the HOME PAGE for example.
    Is the wp_reset_query well done?
    Thanks for the support!

    Posted 1 year ago #
  6. Elliott
    Support

    Hello Victorross,

    When I am viewing your homepage this is the title that I am getting,

    <title>TipicoPortalCorrientes.com</title>

    And on your other pages the title looks something like this,

    <title>Coronel Carreta « PortalCorrientes.com</title>

    That is what you are wanting correct?

    Posted 1 year ago #
  7. Victorross
    Member

    Hi Elliot!
    1) In the homepage title have to be: PortalCorrientes.com
    2) In a post title have to be: (really post title) << (category for the post) << PortalCorrientes.com ... or it can be (category for the post) << (really post title) << PortalCorrientes.com (i just change the order)
    2) In the categories pages title have to be: (category) << PortalCorrientes.com

    So, the last post i do is "Dom 10" on category "Tipico"

    1- If you go to the last post: http://www.portalcorrientes.com/2011/04/10/dom-10-13/
    2- You get TipicoDom 10 << PortalCorrientes.com

    1- If you go to the category: http://www.portalcorrientes.com/category/categorias/restaurantes/tipico/
    2- It is ok you get: Tipicio << PortalCorrientes.com

    1- If you go to the home: http://www.portalcorrientes.com/
    2- You get: TipicioPortalCorrientes.com it is not ok

    So i want to get right the Tipico << Dom 10 << PortalCorrientes.com for the post title
    And in the homepage just PortalCorrientes.com

    Can this be done? Can you help me to get it?

    Hope you understand me :D

    Posted 1 year ago #
  8. Ruderic
    Support

    Hello,

    Have you tried a SEO plugin like "Yoast SEO". They generally include user interfaces for this kind of tasks.

    Posted 1 year ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme