Where do I put this variable?

I have created the following mu-plugin mu-plugins\post-registration-redirect.php:

<?php
/*
Plugin Name:  Post Registration Redirect
Description:  Redirect non-admins to submit-place page after logging into the site.
*/

function submit_place_login_redirect( $redirect_to, $request, $user ) {
    if ( !is_wp_error($user) ) {
       return WP_HOME.'/submit-place/';
    } else {
        ...
    }
}
add_filter('login_redirect', 'submit_place_login_redirect', 10, 3);

/submit-place/ is a URL Slug of a WordPress page (the page displays a form to signed in users).
Question: what are the best options to replace hardcoded '/submit-place/' with a variable?

My main concern:
If I update my WordPress Page slug to something like /new-place/ three months later my redirect will break and I won’t even notice it :frowning:

How about using get_permalink with the page ID?
return get_permalink(10); - 10 being an example page ID.

Now you can change the page slug whenever you want, but the page ID will never change.

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.