Suppose in the site there are frequent links to another website, always tree same, say Wikipedia. Is there a way to write links to Wikipedia in a shortened way, and tell wordpress to translate it?

Example: something like [wiki]/geography shorthand for en.wikipedia.org/wiki/geography


Sure, you're looking for the shortcode API. That would enable you to write a short piece of code that does exactly what you want. As easy as this in your functions.php:

function wpse246274_wiki( $atts ) {
  $link = "http://en.wikipedia.org/wiki/" . $atts['link'];
  return $link;
add_shortcode( 'wikilink', 'wpse246274_wiki' );

Which you would use like this in your post:

<a href="[wikilink link='geography']">Geography</a>

You could even leave out the attribute and just use

<a href="[wikilink]geography">Geography</a>

But that doesn't look as elegant.

  • Thank you for the answer. I have an additional question: what if I want a shortcode for my site URL, in a way that does not depend on the actual URL? (using get_site_url() maybe?) Would it be possible? – geodude Nov 19 '16 at 0:22

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.