Support » Developing with WordPress » Custom meta tags

  • Hi!

    I’m trying my first steps with WP (currently installed locally only for testing, so can’t show anything).

    I have set up a child theme and added the following code to functions.php for setting up a custom meta tag “description”:

    /* Benutzerdefiniertes Feld für Meta-Tag "Description" einfügen. */
    function add_custom_meta_description() {
    global $post; ?>
    <meta name="description" content="<?php
        if ( get_post_meta($post->ID, "description", true) !='' )
            {echo get_post_meta($post->ID, "description", true);}
            else
            {echo "alternative";}
        ?>"/>
    <?php }
    add_action('wp_head', 'add_custom_meta_description', 1);
    

    “description” is a user-defined field I set up for each post.

    This method works well on pages and posts. The static homepage I’m using is showing “alternative”.

    Now I want to use the “alternative” text also on taxonomy pages (categories, keywords, search results). But it shows the meta tag description of the first post appearing on the concerned page instead of.

    I would like to do the following:

    1. Either remove “description” tag from taxonomy and search results pages completely. Maybe adding a <META NAME=”ROBOTS” CONTENT=”NOINDEX,NOFOLLOW”> ?

    Not sure what the SEO experts say about this ? I think that it is good to have such pages involved in search engines, but read on some SEO websites this may cause duplicate contents.

    2. Or use the “alternative” text from my code snippet above for category/keywords and search results pages.

    Here it would be nice to include the category name, keyword or search query in the meta tag, e.g. “This page contains all results for your search ‘xxx’.”.

    I know that this could be done with SEO plugins. But all I checked (Yoast and All-in-one) are just bloated doing less more than adding a description meta tag. And doing this myself – my hope – I gain more control.

    Well, hope you can assist.

    Mark

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s a slew of template tags like is_search(), is_category(), is_single(), etc. that you can use to form conditional structures that vary the output based on the condition.

    As far as using nofollow tags etc, I believe the canonical link tag will take care of preventing duplicate content SEO issues. I don’t have any concerns on my sites. I’m sure there may be plenty of others that will disagree. As with anything SEO related, do you own research and decide for yourself. Everyone is basically guessing, no one knows for sure, and the landscape is constantly changing.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom meta tags’ is closed to new replies.