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?)


1 Answer 1


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.

  • Great to hear... can you mark it as solved then please?
    – Katrina
    Aug 1, 2014 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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