Snippet: Enable WPBakery on New Posts & Pages for Administrators
Currently, WPBakery has a limitation where users with the Administrator role cannot set the builder to load by default when creating new posts or pages. The snippet below provides a workaround by adding the necessary redirection logic. Hopefully, a future update will address this and allow administrators, like all other roles, to have WPBakery open by default when creating new posts and pages.
add_action( 'admin_init', function() {
if ( isset( $_GET['wpb-backend-editor'] )
|| ! isset( $_SERVER['REQUEST_URI'] )
|| wp_doing_ajax()
|| ! function_exists( 'vc_check_post_type' )
|| ! current_user_can( 'administrator' )
) {
return;
}
global $pagenow;
if ( 'post-new.php' !== $pagenow ) {
return;
}
$post_type = isset( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : 'post';
if ( ! vc_check_post_type( $post_type ) ) {
return;
}
$request_uri = sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) );
$url = add_query_arg( 'wpb-backend-editor', '', $request_uri );
wp_safe_redirect( $url );
exit;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
We recommend Code Snippets (100% Free) or WPCode (sponsored)