1

I made a WordPress plugin, so now what I want is, I want to set a logic like if a certain theme is active, then load the plugin. Else, only keep the plugin activated, but don't apply any changes on the site. Any idea how can I achieve that? Sorry if I sound very nerdy :')

2 Answers 2

1

Use get_stylesheet() to get the directory name of the theme being used. If a child theme is being used you can determine the parent with get_template().

At the top of the plugin file you can simply return early if the value is not what you want.

if ( 'my-theme' !== get_stylesheet() ) {
    return;
}
0

You can use the wp_get_theme() function to get information about the active theme and specify its name.


add_action('init', 'pre_function_test');
function pre_function_test()
{
    $var = wp_get_theme();
    $theme_name = $var['Name'];
    if( $theme_name == 'Hello Elementor'){
       wp_die('is theme verify !');
    }
}

Here my theme name is Hello Elementor and my condition is executed.

Note: You can see the theme name from the theme directory and style.css file.

The wp_get_theme() function returns the current theme information.

See in this picture:

get wordpress theme name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.