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 *

 

🕒 Quick and healthy meal? A perfect #keto bowl: a base of green vegetables, a protein (chicken, fish), a healthy fat (avocado, olive oil), oilseeds (chia, squash). Ready in 10 minutes. 👉 The complete guide to the ideal diet on http://blooness.com

💪 Keto ≠ 0 carbs.
Vegetables, berries and nuts are smart carbs that are compatible with a keto-Mediterranean diet. #KetoDiet
👉 Find the complete guide to the ideal diet on http://blooness.com

Load more

Don't miss business advice by email

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

en_USEN