... or is there a way to insert links similarly to Drupal with pathauto, that is:

I want to set links in html like this:


and Wordpress to process at runtime it and display the pretty url


Also I don't like the idea of putting full url's as the website can run on several server (at least during dev time)

  • do you mean pretty permalinks? – Milo Aug 27 '13 at 15:56
  • I have pretty permalinks activated and they worked fine. I would like to avoid hardcoding html links so the permalink structure can change in the future without breaking anything – znat Aug 27 '13 at 16:48
  • You can already insert links referencing the post ID and they will forward to the pretty permalink. The "get shortlink" button shows you this URL when editing a post. are you saying you want those links converted to the pretty version before the page is output to the browser? – Milo Aug 27 '13 at 16:57

When writing html in the code, if you use

<a href="<?php echo get_permalink(123); ?>"></a>

The url outputted is


if you deactive pretty permalinks or, if you active pretty permalinks it change automatically according to your permalink structure.

You never have to hardcoding url in Worpress when writing html in plugin / template files.

If you intend when you have to add a link in the posts content, using the link feature from worpress editor, and "Or link to existing content" option (see image below)

worpress editor link feature

The link that is putted in the html, yes, is hardcoded, but using the current rewrite structure. If you change this structure in the future the link stay the same in the html, but Wordpress is clever enough and your link still works! (I'm sure it works, but I'm not sure how: if I'm not wrong a 301 redirect will be maden).

However if after changing url structure you hate having in the post content urls with old structure (even if they works), you can create a shortcode, like

[post id=123]

that outputs the current permalink for the post.

Make this shortcode works is easy, however, someone has already do the work... see here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.