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;
}
  short code for show all post on a page || wordpress show all post by shortcode
  This function is useful for  WordPress developer just copy and paste this code in your functions.php  file and save file. And just put this short code in your widget   [show_posts posts="1" show_cat="true" order="ASC"] function short_code($atts){         ob_start();  //$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');        extract(shortcode_atts(array(       'posts' => 1, 		 'cat'=>'', 		   'show_cat'=>false, 		  'order'=>'DESC', 		   'post_id'=>'' 		       ), $atts)); 	  $args = array(     'post_type' => 'post',     'post_status' => 'publish',     'category_name' => '',     'posts_per_page' => $posts,     'orderby'=>$order ); 			 	 if( empty($post_id))  	 { 		 $post = get_post($post_id); //assuming $id has been initialized         setup_postdata($...
 
 
 
0 Comments