Actions, functions and conditionals

When developing themes and plugins it is sometimes neccesary to add some functionality to some hook using conditional statements. Example: function my_custom_function() { if( is_home()) { <—what should the function do—> } } add_action( ‘some_hook’, ‘my_custom_function’ ); To my understanding, whenever any other condition exists (is_home return false), the content of the function is not … Read more

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

One of my WordPress themes requires a few third party plugins to run correctly. Most of the times I used to call functions from third party plugins using conditional statements like if(function_exist(‘plugin_function’)) { plugin_function() // do something } suppose though I need to use extensively one plugin through many files of my theme… I would … Read more

Conditional tag to check if ‘page.php’ is being used?

I’m trying to check whether the page.php template is being used or not. I’ve tried is_page_template( ‘page.php’ ) but it doesn’t work. I also can’t use is_page() because I only want to do something when page.php is used, and not when some other custom Page template is used. Please let me know about this and … Read more

Conditional for single-{post-type}.php

Please help with this code for custom post type “video”: If is single-video.php page { list custom-taxonomy of video. Example actors } Else { do nothing } I´m tried with is_single, is_singular, is_page_template but imposible. 1 According to the WordPress conditional docs it should be: if ( is_singular( ‘video’ ) ) { // do conditional … Read more

Toggle admin metabox based upon chosen page template

I’d like to have a custom field interface show up only when a certain template is assigned to a particular WordPress page. Any ideas? 2 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 … Read more