Added Permalinks Shortcode on WordPress


Sponsored Links




WordPress is: Themes, Plugins, Widget, Shortcode, PHP and GPL Licensed. Did you know that, beside Widgets, Another useful WordPress API is shortcode, and now I will show you how to added permalinks shortcode into our WordPress site. Why this shortcode is useful? because with permalinks shortcode The generated URL will be updated automatically, when original permalinks on page or post change.

How To Added Permalinks Shortcode

How To Added Permalinks Shortcode

Let’s get started, write down permalinks shortcode functions on your functions.php in your current theme

function do_permalink($atts) {
	extract(shortcode_atts(array(
		'id' => 1,
		'text' => ""  // default value if none supplied
    ), $atts));

    if ($text) {
        $url = get_permalink($id);
        return "<a href='$url'>$text</a>";
    } else {
	   return get_permalink($id);
	}
}
add_shortcode('permalink', 'do_permalink');

This code below using get_permalink() functions, it’s standard WordPress functions and created shortcode version with code above.

How to use permalinks shortcode? Follow this tutorial

<a href="[permalink id=49]">Basic Usage</a>

Or you can use this method too

[permalink id=49 text='providing text']

Thanks for DigWP for share this code, and I hope tutorial added permalinks shortcode is useful for your blog and more easy to added inlinks between your content (post or pages).

Please notes, this is only sample how we can make a good deal with WordPress shortcode. We can made more complicated shortcode if we need it.

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net


75 Responses to Added Permalinks Shortcode on WordPress

  1. Jared says:

    That’s pretty cool thanks. :)

  2. moonpixel says:

    excellent , this is what I was looking for!!! thanks

  3. Dan says:

    Do you know of a plugin which will help me automatically change my slugs links because I’ve tried SEO post link, SEO slugs and more and can’t get it to do it on auto?

  4. Pingback: WordPress Shortcode Best Practice « Post Your Content in PostFarm

  5. Perry says:

    Of course, my opinion is that free press release distribution sites (like ours) are the most effective ways at building links and bettering SEO.

  6. This is great news for all blogger using wordpress.

  7. WordPress 2.5 is otherwise called as Shortcode API which are small functions that helps us to create macro coding to post a content. Trivial shortcode looks like [gallery] and it is easy to create.

  8. These permalinks require a lot more changes than suggested especially with wordpress. I really appreciate your efforts !

  9. B SEO says:

    RE: Shortcode
    Wp Tricks
    Firstoff Thanks – also excuse my ignorance but is the same thing not achieved by altering the permalink structure in WP Admin?

  10. Fantastic tutorial. Easy and understandable. Thanks.

  11. panos says:

    I’m trying to create a simple shortcode to show the post ID in my post. Something like [post_id], can you help me with the function php code??? Thank you in advance!

  12. Great, this is what I’ve been looking for. I’m creating a free theme for the moment and this was one of my problems! Solved! Thanks!

  13. Casino Tests says:

    Is there a solution to a similar problem with images and/or called in files? Right now I’m working on a theme (in a test location on a sub directory) and I want to be able to link in my header to a .js file without needing to go back and change that. I’m having the same prob with ’s too.I hope this question wasn’t too far off topic.

  14. hiwaar says:

    Thank you for the useful read. keep on!

  15. Thanks a lot!
    i had use WP for years and never hear about the shortcode:(

  16. Sorry if this is off topic but I am totally new to PHP / MySQL / Programming in general. Anyone know a good place to get started learning?

  17. Web design is similar (in a very simplistic way) to traditional print publishing. Every website is an information display container,

  18. Thanks for the step by step guide, now it will be easier for me to edit the short code on my wordpress hosted site.

  19. Thanks for the info dude. You have shared the thing which i was searching for a very long time. I am going to add this short code to my blog. Thanks for the info. I hope you ‘ll share some other informative posts with us.

  20. Hey thanks so much for this. Finally.

  21. Mazda says:

    Thanks a lot!
    i had use WP for years and never hear about the shortcode:(

  22. Fantastic tutorial. This is great news for all blogger using wordpress installers.

  23. I had a problem with permalinks, but when I upgraded to wp 2.9 it allows you to simply add in the desired format, which I got from the org site. They are great and this is helpful.

  24. Pingback: Pide ya el Ubuntu 8.10: Intrepid Ibex

  25. Краник says:

    Do you know of a plugin which will help me automatically change my slugs links because I’ve tried SEO post link, SEO slugs and more and can’t get it to do it on auto? Thanks

  26. Mandy says:

    Thank you! I’m teaching myself wordpress at the moment and appreciate the article.

  27. Using Word Press we can made more complicated short code if we need it.

  28. Hi,
    thank you – i will try it today in a new Blog.

  29. Do you know of a plugin which will help me automatically change my slugs links because I’ve tried SEO post link, SEO slugs and more and can’t get it to do it on auto

  30. The plugins are very nice. They enhance the look of the wordpress. Thanks for the hard work

  31. nuvi 255 says:

    Thanks ive been wondering how to add these permalinks for ages!

  32. thanks, will use it on my blog

  33. Thanks for this excellent tutorial. Very easy to follow. Many thanks.

  34. Maryln Tracy says:

    This is great news for all blogger using wordpress.

  35. glad to see this tutorial, and ak hope to try it without any problems. thanks

  36. This has great content for using wordpress.which are small functions that helps us to create.Its very easy to follow.

  37. Wta Health says:

    Thanks for this excellent tutorial. Very easy to follow. Many thanks.

  38.  NY SEO says:

    A shortcode is a WordPress-specific code that lets you do nifty things with very little effort. Shortcodes can embed files or create objects that would normally require lots of complicated, ugly code in just one line.

  39. Great, simple to follow article!

  40. This looks great. I can’t wait to try it out.

  41. thanks for the permalink shortcodes articles. It help me a lot :)

  42. Fantastic Work..Hats off!!

  43. i have tweak WP over 6 month..

    but i don`t know this before.. thanks for sharing this dude :)

    it`s help me a lot

  44. I got the details about the shot code on word press.This was great article.

  45. determity says:

    wow….but for wordpress.com or wordpress.org???

  46. Trampolines says:

    I got this update from WP Candy, StudioPress the first released Premium Theme I ever know merger with CopyBlogger LLC. [.....]

  47. Kavita says:

    Thanks for tye useful code

  48. micahel says:

    There are so many useful WordPress API and with WordPress being so easy to install and uses there is really nothing better when it comes to care-free blogs. Kinda a set it and forget it type of blog engine.

  49. One of the best shortcode tut’s I’ve seen in a while. Will be linking to it from my site!

  50. Very nice! Thanks a lot. I modified it slightly to allow for multiple words in the link text. Separate words with _ and then use str_replace() to convert _ into spaces before outputting the final link.

  51. ektel blog says:

    wordpress is the best….the pulgins makes it better

  52. I’ve tried to add permalinks shortcode into my WordPress site but just can’t get it to work properly. Maybe i need to do changes or just missing sth.

  53. Permalinks shortcode is a great API, thanks for making its use clearer.

  54. Shoemall says:

    I think permalinks shortcodes definitely clean up the image of your wordpress blog. I have been so happy with wordpress!

  55. Daylilies says:

    wordpress is the awesome… URL will be updated automatically!!! Nice.

  56. This a new reason why wordpress is the best in the world…thanks !

  57. Very intersting post. it’s look easy

  58. JamesT says:

    I like this shortcode technique a lot and it’s given me a few ideas for expanding it.

  59. This a new reason why wordpress is the best in the world…thanks !

  60. sankom says:

    I like this shortcode technique a lot and it’s given me a few ideas for expanding it.

  61. gain max says:

    Very nice! Thanks a lot. I modified it slightly to allow for multiple words in the link text. Separate words with _ and then use str_replace() to convert _ into spaces before outputting the final link.

  62. den says:

    Very nice! Thanks a lot. I modified it slightly to allow for multiple words in the link text. Separate words with _ and then use str_replace() to convert _ into spaces before outputting the final link.

  63. Horoscopo says:

    Very Nice, Thanks, Enriched.

  64. Susan says:

    Great post, shortcode can be pretty confusing.

    Thanks.

  65. This a new reason why wordpress is the best in the world…thanks !

  66. Thanks for the tip, i use it now for all my blogs and prestashop

  67. sms gratuit says:

    I love your blog but your rss doesn’t works :(

  68. Very nice! Thanks a lot. I modified it slightly to allow for multiple words in the link text. Separate words with _ and then use str_replace() to convert _ into spaces before outputting the final link.

  69. Bonner says:

    Excellent writeup.I will bookmark this site. We are intending to sign up to this feed also.

  70. think cash says:

    Good tip, I like it and this is best tip of the day.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>