• By default the tags added to a post appear at the bottom of each post. I would like to move them to the entry-meta section, next to the categories.

    How can I do this?

    I guess I’ll have to edit the code for that, so I created a child theme.

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

    You’ve completed the first step, which is to create a child theme. Great!

    The next step is to copy the function that’s generating the content in the entry-meta section – dyad_entry_meta() – to your child theme’s functions.php file:

    function dyad_entry_meta() {
    	// Hide category and tag text for pages.
    	if ( 'post' == get_post_type() ) {
    		/* translators: used between list items, there is a space after the comma */
    		$categories_list = get_the_category_list( esc_html__( ', ', 'dyad' ) );
    		if ( $categories_list && dyad_categorized_blog() ) {
    			echo '<span class="cat-links">' . $categories_list . '</span>'; // WPCS: XSS OK.
    		}
    	}
    }

    The above is generating a list of categories to display in that section of your posts.

    You could use the above to create code to bring in a list of your tags:

    $tags_list = get_the_tag_list( '', '' );
          if ( $tags_list ) {
            echo '<span class="tag-links">' . $tags_list . '</span>'; // WPCS: XSS OK.
    }

    All together, that would leave you with the following function:

      function dyad_entry_meta() {
        // Hide category and tag text for pages.
        if ( 'post' == get_post_type() ) {
          /* translators: used between list items, there is a space after the comma */
          $categories_list = get_the_category_list( esc_html__( ', ', 'dyad' ) );
          $tags_list = get_the_tag_list( esc_html__( ', ', 'dyad' ) );
    
          if ( $categories_list && dyad_categorized_blog() ) {
            echo '<span class="cat-links">' . $categories_list . '</span>'; // WPCS: XSS OK.
          }
    
          $tags_list = get_the_tag_list( '', '' );
          if ( $tags_list ) {
            echo '<span class="tag-links">' . $tags_list . '</span>'; // WPCS: XSS OK.
          }
        }
      }

    You would also need to style the list of tags using CSS. The following worked well on my own test site:

    .has-post-thumbnail .entry-meta .tag-links a {
        background: #678db8;
        color: #fff;
        padding: 13px 15px;
        font-size: 1.3rem;
        margin-right: 5px;
    }

    Hope that helps point you in the right direction! ??

    Thread Starter Hugo Callens

    (@prettiggeleerd)

    This worked like a charm, thank you so much!

    You’re most welcome, Hugo!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Move tags to entry-meta’ is closed to new replies.