This morning I needed a quick way to have the permalink for a WordPress post as part of the text. Sure, there’s already the get_permalink()
method, but I don’t have PHP parsing turned on in WordPress. So I made a very small shortcode function.
add_shortcode('permalink', function() {
return get_permalink();
});
If you add this little snipped to your theme functions.php
file you’ll add a [permalink]
shortcode to your WordPress site that kicks out the actual link to the page you’re on.
Yes, it could have been built as a plugin instead of going into functions.php
, but that seemed like overkill for something so small.
Be First to Comment