wp_redirect not working from shortcode function

Why does it need to be a Shortcode? Looks like a XY Problem. You’re already inserting the shortcode manually in the edit screen. Use a Custom Field instead and hook earlier where you can actually do the redirect. add_action( ‘template_redirect’, function(){ global $post; $redirect = get_post_meta( $post->ID, ‘redirect’, true ); if( $redirect ) { wp_redirect( … Read more

Redirecting Subscriber Users to the home page after updating their profile

Hope this links will help you, link OR This is the function that you need: add_action( ‘profile_update’, ‘custom_profile_redirect’, 12 ); function custom_profile_redirect() { wp_redirect( trailingslashit( home_url() ) ); exit; } You can also set it for a specific User Role: add_action( ‘profile_update’, ‘custom_profile_redirect’, 12 ); function custom_profile_redirect() { if ( current_user_can( ‘subscriber’ ) ) { … Read more

how to block direct access to multiple thank you pages?

I have solved the issue by myself. I am posting the solution here in case if someone gets the same problem. function wpse15677455_redirect() { $ref = wp_get_referer(); if (is_page(1911) && $ref !== “https://www.example.com/contact”){ wp_redirect( get_home_url() ); } else if(is_page(1269) && $ref !== “https://www.example.com/contact-form-2”){ wp_redirect( get_home_url() ); } else if(is_page(1825) && $ref !== “https://www.example.com/contact-form-3”){ wp_redirect( get_home_url() … Read more

Redirect to Referring URL after Login

Your code is completely flawed – not to mention you can’t redirect to the HTTP referer after login… because the referer is now the login page. Instead, use the login_redirect filter: add_filter( ‘login_redirect’, function ( $redirect_to, $requested_redirect_to ) { if ( ! $requested_redirect_to ) { $redirect_to = wp_get_referer(); } return $redirect_to; }, 10, 2 ); … Read more

Controller functionality – if user is not logged in send them to specific page (not wp_login)

The reason why you are getting a not redirecting properly message is because you are creating an endless loop of redirects. They get redirected to /public but because they are not logged in they get redirected again and again and again… Try this code instead: if( ! is_user_logged_in() && ! is_page(“public”) ) { wp_redirect( site_url(“/public”) … Read more

Custom pagination structure

After searching here and there, probably I found solution. (Don’t know if I am doing wrong in WP terminology!) Page was redirecting from …/page5 to …/page/5, because of redirect_canonical function resides in WordPress core. So I further searched for altering it by hook. Few people were saying remove redirect_canonical filter by adding this in code: … Read more