How to make plugin required in a wp theme without using php conditional statements when calling an individual function from that plugin?

is_plugin_active() is rather fragile: it will break when either the plugin author renames the main file or when the user renames the plugin’s directory or main file. It’s better to check if a certain public function exists. To avoid having to make that check each time you need some of the plugin’s functionality, you could … Read more

the_content and is_main_query

To be honest, the function in_the_loop() is what you are looking for: add_filter( ‘the_content’, ‘custom_content’ ); function custom_content( $content ) { if ( in_the_loop() ) { // My custom content that I add to the_content() } return $content; } What in_the_loop does is to check if global for $wp_query (that is the main query object) … Read more

Toggle admin metabox based upon chosen page template

The best way to approach this situation is via JavaScript. That way, whenever the selected value changes, you can instantly hide/show the related metabox. Use wp_enqueue_script() in functions.php to load a custom JavaScript file in the admin area: add_action(‘admin_enqueue_scripts’, ‘my_admin_script’); function my_admin_script() { wp_enqueue_script(‘my-admin’, get_bloginfo(‘template_url’).’/my-admin.js’, array(‘jquery’)); } The script itself, which requires jQuery, simply hides … Read more