Y
Y
Yuri Kirillov2017-08-14 11:11:15
metadata
Yuri Kirillov, 2017-08-14 11:11:15

How to display tags inside a post?

Good afternoon!
In WordPress, each post has a list of tags to display inside the_content() itself , in the middle of the text.
Connected PHP execution inside posts and through the_tags() output; , but does not work (something prevents the list of labels from being read) ...
How can I implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2017-08-14
@kirilloff-iura

eval() should not be used. Never.
Such moments are solved through shortcodes.
1. In functions.php

function post_tags_within_content() {
    global $post;
    $tags = get_the_tag_list( '<p>'Tags: , ', ', '</p>', $post->ID );
    return $tags;
}
add_shortcode( 'tags', 'post_tags_within_content' );

2. Use in post content:
3. Result:
...
<p>Tags: tag1, tag2, tag3</p>
...

while tag1, tag2, tag3 will be links to the corresponding terms.
The get_the_tag_list() function parameters are in the documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question