WordPress.org

Forums

How to use Post Tags for Meta Keywords (4 posts)

  1. krystiank
    Member
    Posted 5 years ago #

    Is there any way I could reuse my Post Tags in Meta Keyword tag.

    I tried this but, it breaks my page layout.
    <meta name="keywords" content="<?php the_tags(); ?>

    Thanks

  2. zoleytaylor
    Member
    Posted 5 years ago #

    try get_the_tags() ;) it works the same as the_tags() but without linking each tag...

  3. krystiank
    Member
    Posted 5 years ago #

    Thanks, I tried it but it did not display anything. It's just empty.

  4. zoleytaylor
    Member
    Posted 5 years ago #

    yep, you need to echo the name values from the array... i wrote you this code:

    <meta content="<?php
    if( is_singular() ) {
      $keywords = get_the_tags();
      if( $keywords ) {
        foreach($keywords as $keyword) {
          echo $keyword->name . ', ';
        }
      }
    }
    else {
      echo('your, custom, keywords, for, list, pages');
    }
    ?>" name="keywords" />

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.