Permalink shortcode a href link
-
I’m trying to create a link to the current page. I’ve created a shortcode that prints the URL. This works fine. But as soon as I put the shortcode in a link the url is empty and the permalink is displayed as text on the page above where it should be?
I just want to simply link to the current page permalink. This would be easy but WordPress doesn’t allow PHP in the page/post editor.
My shortcode function:
add_shortcode( 'my_permalink', 'my_permalink' ); // The Permalink Shortcode function my_permalink() { ob_start(); the_permalink(2); $permalink = ob_get_clean(); print(urlencode($permalink)); }
[my_permalink]
Produces the permalink as text but<a href="[my_permalink]">link</a>
creates an empty link and permalink as text.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Permalink shortcode a href link’ is closed to new replies.