WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We're using Wordpress as a knowledge base. We just left mediawiki and jekyll for Github pages and reduced the amount of different systems from four to just one. One Wordpress installation for blogging and three for three different knowledge bases for three different products. The advantage is that editors only have to master one system instead of three.

We've set the permalinks to /%postname%/ which makes nice and logical weblinks. In most of the pages we're adding links to other knowledge base pages using the editor. In the popup we're selecting the page to link to. The permalink is added to the page. Since we're constantly working on the Knowledge Base it will happen that the postname changes. This will result in an error 404 on an internel Knowledge Base page linking to the changed post.

Therefor I would like to add page id's (?p=123) instead of the post name. When the link is clicked on the frontend Wordpress seems to be smart enough to rewrite the page id to the /%postname%/ Advantage is that I don't have to change the links in every page. (or can this be done automatic too?)

share|improve this question
up vote 6 down vote accepted

Add that to your functions.php:

function wp_link_query_mod ( $results ){
    if( count( $results ) ){
        for( $i=0; $i<count($results); $i++ ){
            $results[$i]['permalink'] = wp_get_shortlink( $results[$i]['ID'] );
    return $results;
add_filter('wp_link_query', 'wp_link_query_mod');

This hook is only usable since WP 3.7, if you have an earlier version then there is an alternative but it would mean changing a line in WP core files.

share|improve this answer
Thank you ... this solution works like a charm. – hans2103 Jul 31 '14 at 11:58
Great to hear... can you mark it as solved then please? – Katrina Aug 1 '14 at 22:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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