The wp-context package allows you to determine the current request’s context easily.
Install the package and instantiate the WpContext class.
Then you can check the context using WpContext::is() method.
Here is an example:
<?php
use Inpsyde\WpContext;
// Instantiate the class
$context = WpContext::determine();
// Use the WpContext::is() method to check context
if (!$context->is(WpContext::FRONTOFFICE, WpContext::BACKOFFICE)) {
return false;
}Code language: HTML, XML (xml)
https://gist.github.com/laxmariappan/12fba7f207b85b8857bd62a0f50bb61f
Leave a Reply