Create a shortcode for the permalink of a WordPress article

WordPress Multisite 1

I needed to create a shortcode allowing me to display the link to a WordPress article. To do this, here is the code that I added to my functions.php file:

[coded]
add_shortcode('my_permalink', 'my_permalink');
// The Permalink Shortcode
function my_permalink() {
ob_start();
the_permalink();
return ob_get_clean();
}
[/coded]

And all you had to do was use the shortcode [my_permalink] to have the direct link to your WordPress post.

Source.

Ziyad Bachalany

The author

Ziyad Bachalany

Entrepreneur and web consultant in Paris. I managed a group of four restaurants, launched software for restaurateurs, and published WordPress plugins. I build websites, tools, and automations for freelancers, businesses, and SMEs.

Comments

Leave a Reply

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