New answers tagged

0

We can check the $request which is passed to our login_redirect filter-function using url_to_postid. // redirect subscribers if logging in from specific page function wpse381872_login_redirect( $redirect_to, $request, $user ) { // turn the request url into a post-id $request_id = url_to_postid( $request ); if ( isset( $user->roles ) &&...


2

RewriteCond %{HTTP_COOKIE} !.*wordpress_logged_in.*$ [NC] RewriteCond %{REQUEST_URI} ^(.*?/?)purchase.php RewriteRule . https://%{HTTP_HOST}%1/registrationurl [L,QSA] This will result in a 302 (temporary) redirect to /purchaseads//registrationurl - note the double-slash. This double-slash is passed through to the $_SERVER['REQUEST_URI'] variable that ...


0

Nevermind I figured out myself. In case someone needs the solution: You have to enter in Setings>Permalinks Then in case you are using a custom structure select %postname% and it should work I think using Post name structure should solve the problem too


1

The template redirect is most useful for managing the output of theme files. To redirect a non-logged in user when the page loads, attach your function to the 'init' hook. (If you call it sooner than that in the stack, you may get an error because the function definition hasn't been included yet.) In short, if you replace the action hook in the code you ...


0

Reference: After Login Redirection By User Roles In WordPress /*@ After login redirection by user role */ if ( !function_exists('tf_after_login_redirection_by_user_roles') ): add_filter( 'login_redirect', 'tf_after_login_redirection_by_user_roles', 10, 3 ); function tf_after_login_redirection_by_user_roles( $redirect_to, $request, $user ) { ...


1

Check your production site's wp-config.php file for one or both of these lines: define( 'WP_HOME', 'https://example.com' ); define( 'WP_SITEURL', 'https://example.com' ); ...and set them as appropriate if they exist. These constants will override the settings in the database if they're present. See Editing wp-config.php for details.


0

Perhaps something like this? add_action( 'template_redirect', 'not_logged_in_redirect_home' ); add_action( 'do_feed', 'not_logged_in_redirect_home' ); function not_logged_in_redirect_home(){ if ( is_user_logged_in() ){ return false; } if ( ! is_home() // use this option if you show blogs posts on the home page // ! ...


1

The problem is the variable $sountry - and this is because of something called variable scope - https://www.php.net/manual/en/language.variables.scope.php - the variable is only available within the function, as you do not "export" it or make it globally available - here is an update to your functions to show how this might work: function ...


Top 50 recent answers are included