Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using theme Twenty Eleven and am trying to add a vote up script in the content.php which only displays on a certain category.

share|improve this question
    
add comment

1 Answer

up vote 2 down vote accepted

you can do that in multiple ways .. For example you can do a conditional in the PHP itself with a wp built in function :

if ( in_category( 'my-category' ) {
 //Do something
}

or for example, if the script is a javascript you could load the script in a conditional way , so it would not load where it is not needed - it will save also some processing time (change the condition to what you want).

    function dl_add_js_conditional() {

        if (!is_admin()) { //if is not admin - will load only on front-end
            wp_register_script('myscript_name_js', get_bloginfo('stylesheet_directory') . '/js/myscript_file.js', array('jquery'));
            wp_enqueue_script('myscript_name_js');
        }
if (is_home()) { //will load only on home
            wp_register_script('myscript_name_js', get_bloginfo('stylesheet_directory') . '/js/myscript_file.js', array('jquery'));
            wp_enqueue_script('myscript_name_js');
        }
    }
    add_action('init', 'dl_add_js_conditional');

Or , you can also do the detection / condition in the script itself (you did not specify what script you use, Jquery, Javascript or other)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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