Deprecated: sanitize_url is deprecated since version 2.8.0! Use esc_url_raw() instead. in C:\Services\WCMP\www\site04_kknbb\wp-includes\functions.php on line 4861

WordPress View Frontend as a Guest

This is particularly useful when using cache like Cloudflare, and don’t want the editor’s frontend page view to be cached.

//admin or editor temporarily logout when on frontend
function front_guest_view() {
	global $current_user;
	//if its admin panel, don't logout
	if(is_admin() or is_customize_preview() ) 
	//if user can edit post, show a guest frontend page
	if( current_user_can( 'edit_posts' ))
		$current_user = -1 ;
add_action( 'template_redirect', 'front_guest_view', 20 );

Leave A Comment

CAPTCHA ImageChange Image