MY BLAH BLAH BLOG

Here, I’ll be sharing insights and experiences on a variety of topics close to my heart. From the intricacies of web design and tips for mastering Divi, to exploring the immersive worlds of video games, and even reflections on life itself, this blog is a canvas for my passions and musings. Join me on this journey as we delve into the digital realm and beyond.

Home 5 Tutorials 5 WordPress TAGS Shortcode

WordPress TAGS Shortcode

Φεβ 21, 2018 | Tutorials | 0 Σχόλια

So I’ve been using DIVI theme (by Elegant Themes) for quite a while and I needed to find a way to add the post’s tags inside the post’s body. Since Divi doesn’t have this module I had to make my own shortcode. As we can see in the WordPress Codex the function that returns the tag list we want is get_the_tag_list().

Usage

<?php $tag_list = get_the_tag_list( $before, $sep, $after, $id ); ?> This function does not display anything – if you want to put it straight onto the page, you should use echo get_the_tag_list();. Alternatively, you can assign it to a variable for further use by using $foo = get_the_tag_list();. The variables are all optional. You can use HTML inside each of the fields.

Parameters

$before (string) (optional) Leading text. Default: ‘ ‘ $sep (string) (optional) String to separate tags. Default: ‘ ‘ $after (string) (optional) Trailing text. Default: ‘ ‘ $id (integer) (optional) Post ID. Default: Current post ID

Create your own shortcode

Just add the following code in your theme’s functions.php file:
function wp_divi_tags() { return get_the_tag_list(‘<p>Tags: ‘,’, ‘,'</p>’); } add_shortcode(‘tags’, ‘wp_divi_tags’);
Then just use the SHORTCODE  anywhere you want.