Support » Plugin: Tag Pages » Re-opening topic: Show tags in meta in head?

  • Resolved stoicattempt



    I read [email redacted] question in this support section. He/She needed something like:

    <meta name="keywords" content="bread,soup,beer,marmelade">

    … where the content attribute is completed with tags using the Tag Pages Plugin

    I understand you prefer to leave this issue to other template developers, but I was wondering whether you would be willing to reconsider. You might have stumbled upon the answer over the years.

    I’ve tried various functions to get WordPress to print the page tag in a <meta> field, but no luck. Note: I’m quite new to PHP.

    1. The following lines print too much, including some unwanted html:

    <meta name="page-tags" content="<?php the_tags( '', ', ', '' ); ?>">
    <meta name="page-tags" content="<?php the_tags(); ?>">

    2. These ones print nothing:

    <meta name="page-tags" content="<?php get_the_tag_list(); ?>" >
    <meta name="page-tags" content="<?php tag_description(); ?>" >

    3. And I’m still looking into these:

    get_term_link( $tag, 'post_tag' );
    wp_get_post_tags( $post_id, $args );

    All hints and clues are welcome!

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author BjornW


    Hi stoicattempt,

    Somehow I completely missed your question, my apologizes. I understand your question and need for this, but core WordPress already offers a solution using the functions you’ve described.

    If you’re new to PHP it may be daunting at first, but using the core functions in combination with some sprinkles of your own PHP can solve this problem better than any plugin. If you need some assistance feel free to let me know.


    Thanks for your reply.

    I got the job done with a code snippet from a StackExchange developer called Milo. This is what I’ve added to my child theme’s functions.php file, it is what I’m using to print the tags in my <body> classes:

    function add_tags_to_body_class( $classes ) {
        if( ( is_page() || is_single() )
            && $tags = get_the_tags( get_queried_object_id() ) ){
            foreach( $tags as $tag ) {
                $classes[] = $tag->name;
                // $classes[] = 'tag-' . $tag->name;
        // return the $classes array
        return $classes;
    add_filter( 'body_class', 'add_tags_to_body_class' );


    Plugin Author BjornW


    Hi stoicattempt,

    Great to see you’ve achieved your goal! I will set this topic to resolved so others know it is solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Re-opening topic: Show tags in meta in head?’ is closed to new replies.