Skip to content

WordPress permalink shortcode

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.phpfile 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.

Published inWordPress

Be First to Comment

Leave a Reply

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