Add WordPress hook outside of Plugin or Theme

We have the following code that is used to hide our core theme so that it can’t be enabled directly and you can only enable the child themes from the WordPress Dashboard.

function hide_core_theme($themes) {
    unset($themes['nacore']);
    return $themes;
}
add_action('wp_prepare_themes_for_js', 'hide_core_theme');

However if you put this code inside the functions.php file of either the Parent or Child theme it will only hide the core theme when one of them is enabled… e.g. if someone was to turn on another theme the core theme would appear again.

Another option is to add this code inside a custom plugin… but it means having it enabled and a user could always disable this plugin to get around it… plus we’re not too keen on having a plugin to turn off a theme as it feels pretty detached.

Is it possible to add some hooks that are outside of a Theme or Plugin? And therefore are called regardless of what themes or plugins are enabled?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You want a “Must Use Plugin”. Any PHP files placed in wp-content/mu-plugins will be run automatically, and can only be ‘deactivated’ by removing the file.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x