Durga Prasad Kundu
Durga Prasad Kundu

Reputation: 51

Wordpress, how to get the tag slug from tag name in a post page?

In a single post, how to get the tag slug & tag id of tag used for that particular post.

For e.g; I have a post "Hello World!" tagged in "My Post". How to get the slug "my-post" in "Hello World!" post page(i.e; single.php file).

Upvotes: 1

Views: 2382

Answers (1)

Milap
Milap

Reputation: 7221

$terms = get_the_terms( $post->ID, 'post_tag' );
if ( !empty( $terms ) ){
    // get the first term
    $term = array_shift( $terms );
    echo $term->slug;
}

Reference : https://wordpress.stackexchange.com/questions/130947/get-term-slug-of-current-post

Upvotes: 2

Related Questions