-
-
Save dexit/5bd8f98e3121258a2c474158c8217c15 to your computer and use it in GitHub Desktop.
Better WordPress is_admin()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check if inside WP Admin. Also works in the Block Editor. | |
* | |
* With the introduction of Gutenberg, is_admin() was broken. | |
* This better version will account for the Block Editor (Gutenberg) | |
*/ | |
function mytheme_better_is_admin() { | |
// Check if in Block Editor - see: https://github.com/WordPress/gutenberg/issues/51090#issuecomment-1576570247 | |
if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST && 'edit' === $_GET['context'] ) ) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment