Redirect guest if he tries to access a specific page

You can use template_redirect action to redirect Specific users based on your terms. This action hook executes just before WordPress determines which template page to load. It is a good hook to use if you need to do a redirect with full knowledge of the content that has been queried. You can use is_page function … Read more

How to target specific user role?

get_role is just going to return information about the role. It isn’t going to tell you if the current user has that role. Use wp_get_current_user with a check something like this: function subscriber_redirection() { global $redirect_to; $user = wp_get_current_user(); if (in_array(‘subscriber’,$user->roles)) { // user has subscriber role if ( !isset( $_GET[‘redirect_to’] ) ) { $redirect_to … Read more

How to redirect from various ?page_id= to home page?

You can’t match the query string using a mod_alias RedirectMatch directive. This directive matches against the URL-path only. You need to use mod_rewrite instead, with a condition that checks the QUERY_STRING server variable. For example, at the top of your .htaccess file, try the following: RewriteCond %{QUERY_STRING} ^page_id=\d+$ RewriteRule ^$ / [QSD,R=302,L] The QSD flag … Read more

How to redirect visitor to a custom URL using PHP code in functions.php

First, it is hard to believe that wp_redirect isn’t working, below some (example) code how to use it: function wpse101952_redirect() { global $post; if( /*SOME CONDITIONAL LOGIC*/ ) { //examples: is_home() or is_single() or is_user_logged_in() or isset($_SESSION[‘some_var’]) wp_redirect( /*SOME SPECIFIC URL*/ ); exit(); } } add_action( ‘template_redirect’, ‘wpse101952_redirect’ ); Second, there would be the question … Read more

Change gravity forms confirmation redirect query string to include entry id [closed]

I figured it out. I did have some syntax errors in my code. Should have been add_filter instead of add_action. Also, $confirmation is an array and was never returned. I think my brain was just tired from looking at this for so long. Anyways, here’s what I did to fix it. add_filter(“gform_confirmation”, “confirm_change”, 10, 4); … Read more

Redirect HTTP to HTTPS

I am answering this old question, as it still remains unanswered. Instead of using the plugin, you should use cPanel to redirect HTTP to HTTPS. It will help you to get rid of the infinite redirection loop issue. Follow these steps: Login to your cPanel account. Click on the File Manager. Ensure that public_html directory … Read more

Return to where the user was, after log out

You get the current path with remove_query_arg( ” ). Combine it with site_url(), and you have the full current request URI: $url = untrailingslashit( site_url() ); $url .= remove_query_arg( ” ); Be aware that remove_query_arg() doesn’t return a sanitized value, so you have to use esc_url() if you want to print it to a page. … Read more

https redirect (with .htaccess) redirect loop

I’d steer clear on editing the .htaccess if you’re just updating your website from HTTP to HTTPS. Try an alternative route: First, revert your .htaccess back to the default settings: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # … Read more