WordPress perma links

Ok i made plugin for contact form, thing is i have redirection when form is submited to success page

$location = home_url().'/potvrda-prijave/';
wp_safe_redirect($location);
exit();

thing is when someone change permalinks structure i will get 404, does anybody knows how to grab permalinks change and change my redirection link? something like this

Read More
$location = home_url().'/potvrda-prijave/';

to

 $location = home_url().'id=21';

Related posts

Leave a Reply

1 comment

  1. Since you know the page ID, you can simply use get_permalink():

    $location = get_permalink( 21 );
    

    EDIT: It looks like you don’t actually know the ID…In that case, if you know the title, you can use:

    $location = get_permalink( get_page_by_title( 'Your Page Title' ) );
    

    However, if you’re using wp_insert_post() to create the post in the first place, that function returns the page ID of the added post. So:

    $added_post = wp_insert_post( $my_post );
    $location = get_permalink( $added_post );