add_action('get_header', function() {
if (is_user_logged_in() ) {
if ( is_page( 'about-us' ) ) {
// also tested with 'Apple'
$url = get_home_url();
wp_redirect($url);
}
}
});
Check If User not login than redirect on login page
where you want to check there add this short code [redirect_user]
add_shortcode('redirect_user','check_logred');
function check_logred(){
ob_start();
if (!is_user_logged_in() ) {
$url = get_home_url();
wp_redirect($url.'/login');
}
ob_get_clean();
}
Author base change custom code
add_action('init', 'cng_author_base');
function cng_author_base() {
global $wp_rewrite;
$author_slug = 'profile'; // change slug name
$wp_rewrite->author_base = $author_slug;
}
Change a spacific User slug by custom code
$user_nicename ='shyam-sir-4';
$user_data = wp_update_user( array( 'ID' => $user_id, 'user_nicename' => $user_nicename ) );
if ( is_wp_error( $user_data ) ) {
// // There was an error; possibly this user doesn't exist.
echo 'Error.';
} else {
// // Success!
echo 'User profile updated.';
}
Filter hook author slug .
add_filter( 'author_link', 'modify_author_link', 10, 1 );
function modify_author_link( $link ) {
$link = 'http://example.com/';
return $link;
}
Automatically Log in as Admin without ID password
Automatically Log in as Administrator with a Single Click Automatically Log in as Administrator with a Single Click If you're a WordPress developer or site administrator, you might often need to log in to your site quickly for testing or debugging. Manually entering your username and password can be time-consuming, especially during development. To simplify this process, I’m sharing a handy code snippet that allows you to log in as the first administrator user with just a single click. How Does This Code Work? This code snippet is designed to automatically log you in as the first administrator user on your WordPress site when you add ?dev=1 to your site’s URL. Here’s how it works: Check for the Query Parameter : The code listens for the ?dev=1 parameter in the URL. If it detects this parameter, it triggers the login process. Find the First Administrator : It queries the WordPress database to find the first ...
0 Comments