Last active
October 7, 2020 19:17
-
-
Save fklein-lu/581a83b1baebcabeaf6d53908ebca6ab to your computer and use it in GitHub Desktop.
Gutenberg block development helper function to detect whether a block renders on the frontend or the backend
This file contains 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 | |
/** | |
* Hackish solution to distinguish between block renders on the front end, and the back end. | |
* | |
* In the admin, the global `$wp_query` does not contain a query. We use this to determine whether a rendering is | |
* happening on the front end or the back end. | |
* | |
* @return bool Whether we're in the admin or on the front end. | |
*/ | |
function fk_is_front_end_query() { | |
return ! is_null( $GLOBALS['wp_query']->query ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment