Create a shortcode for the permalink of a WordPress article

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.

Don't miss business advice by email

No spam, just an email when new content is published.

Source.

Leave a Reply

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

Don't miss business advice by email

No spam, just an email when new content is published.

en_USEN