Using WordPress ‘global_terms_enabled()’ PHP function

The global_terms_enabled() WordPress PHP function determines whether global terms are enabled.

Usage

$are_global_terms_enabled = global_terms_enabled();

Parameters

  • None

More information

See WordPress Developer Resources: global_terms_enabled()

Examples

Check if Global Terms are Enabled

Determine if global terms are enabled and display a message accordingly.

$are_global_terms_enabled = global_terms_enabled();

if ($are_global_terms_enabled) {
    echo "Global terms are enabled.";
} else {
    echo "Global terms are not enabled.";
}

Enable or Disable a Feature Based on Global Terms Status

Enable a custom feature only when global terms are enabled.

function custom_feature() {
    // Your custom feature code here
}

if (global_terms_enabled()) {
    custom_feature();
} else {
    echo "Custom feature is disabled because global terms are not enabled.";
}

Conditional Loading of Scripts or Styles

Load a specific script or stylesheet when global terms are enabled.

function enqueue_scripts_based_on_global_terms() {
    if (global_terms_enabled()) {
        wp_enqueue_script('global-terms-script', 'path/to/global-terms-script.js', array(), '1.0', true);
    } else {
        wp_enqueue_script('non-global-terms-script', 'path/to/non-global-terms-script.js', array(), '1.0', true);
    }
}
add_action('wp_enqueue_scripts', 'enqueue_scripts_based_on_global_terms');

Filter Posts Based on Global Terms Status

Filter posts on the frontend based on whether global terms are enabled.

function filter_posts_based_on_global_terms($query) {
    if (!is_admin() && $query->is_main_query()) {
        if (global_terms_enabled()) {
            $query->set('tag_id', '10,20,30');
        } else {
            $query->set('tag_id', '40,50,60');
        }
    }
}
add_action('pre_get_posts', 'filter_posts_based_on_global_terms');

Display a Notice in the Admin Area

Show a notice in the admin area if global terms are not enabled.

function show_admin_notice_if_global_terms_not_enabled() {
    if (!global_terms_enabled()) {
        echo '<div class="notice notice-warning is-dismissible">
                <p>Global terms are not enabled. Some features may not work as expected.</p>
              </div>';
    }
}
add_action('admin_notices', 'show_admin_notice_if_global_terms_not_enabled');