Add more user roles to a PHP logout redirect function [closed]

All you have to do is copy the part in the code that checks which role the user has and redirect somewhere else, like this: function redirect_after_logout( $user_id ) { $current_user = get_user_by( ‘id’, $user_id ); $role_name = $current_user->roles[0]; if( $role_name == ‘administrator’ ) { wp_safe_redirect( site_url( ‘/login/’ ) ); exit; } if( $role_name == … Read more

How to read and write session data?

Assuming you are using WooCommerce (but equivalent to the WC()->cart->is_empty() check can be found for all major well-designed e-commerce plugins): add_action(‘woocommerce_before_checkout_form’,function(){ if (is_user_logged_in()){ $user = wp_get_current_user(); if ( bpprocn_has_incomplete_profile($user->id) ) { // check user’s profile completed or not if ( ! WC()->cart->is_empty() ) { if (wp_redirect(bp_core_get_user_domain( $user->id ) . bp_get_profile_slug() . ‘/edit/group/2’)) exit; } } … Read more

How to Redirect WordPress domain.com/?anyword to 404 Page?

It is, in most cases, a logical thing to show the homepage even when there are querystrings available. Never the less, I’m assuming you have a reason for this. You could try code below to redirect your visitors to your 404 page: if ( isset($_GET) ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( 404 … Read more

How Do I Redirect WordPress Pages but not posts?

You can either add the following code to your functions.php or create a custom plugin with the code. function my_custom_page_redirect() { if (is_page()) { wp_redirect(home_url()); exit; } } add_action(‘template_redirect’, ‘my_custom_page_redirect’); Note – change the URL in wp_redirect() to whatever the ‘specificpage’ is. I just used home_url() in the redirect as an example.