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.

Is it possible to insert links in Wordpress's wysiwyg editor that will convert to pretty permalinks when enabled?

i.e. the links would be this without pretty permalinks:

/?p=13

But with permalinks on, it would become this:

/mypagename/

I'm thinking I'd have to use a shortcode to do that right? Something that would use the ID and wp_list_pages() for pages at least... just thinking about a way to get links in content to work when permalinks are on and off.

Thanks

osu

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here is example of simple shortcode that will take ID as argument and echo permalink for it:

function link_from_id($atts) {

    if( isset($atts['id']) )
        return get_permalink( (int)$atts['id'] );
}

add_shortcode('link', 'link_from_id');

Usage:

[link id=1]

PS by the way non-pretty permalinks will keep working just fine if you enable pretty mode later and, if I remember right, will be redirected to canonical pretty version.

share|improve this answer
    
Thanks for this Rarst, much appreciated - and you're right about non-pretty permalinks working in both contexts. –  Osu Jan 27 '11 at 19:40

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.