Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 4 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 at 11:58
    
Great to hear... can you mark it as solved then please? –  Katrina Aug 1 at 22:51

Your Answer

 
discard

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.