I’m converting an HTML template into a wordpress theme and I’m having some trouble displaying the post tags within the functions.php file. What I would like to do is add the following code into the functions file with the HTML code. I have been trying for a few days now and I have already been to the codex but nothing I try is working.

<div class="tags">
<a href="#" rel="tag">tag 1</a> <a href="#" rel="tag">tag 2</a> <a href="#" rel="tag">tag 3</a> <a href="#" rel="tag">tag 4</a>
</div>

Can anyone please help with this?

5 Answers
5

I think you are searching for the get_tags() function. You would need to place it into the single-post.php (or single.php if your theme doesn’t have a single-post.php) (to find the right template file you can always look up at WordPress Template Hierarchy).

To echo a list of tags with the aboved linked function you would need to use something like:

<?php $tags = get_tags(); ?>
<div class="tags">
<?php foreach ( $tags as $tag ) { ?>
    <a href="https://wordpress.stackexchange.com/questions/152298/<?php echo get_tag_link( $tag->term_id ); ?>" rel="tag"><?php echo $tag->name; ?></a>
<?php } ?>
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *