0

can I check if scripting can be encrypted for specific categories? For example, I would like to encrypt only for http://www.example.com/category/news/education, for http://www.example.com/category/news/dogs, so on and so forth.

Thanks!

Regards, Jeremy

  • 3
    Encrypt what? What are you trying to do exactly? Enqueue a script on a category? ...or? – Adam Feb 8 '16 at 6:57
-2

Write this in your theme's functions.php file

function category_enqueue_script() {
    $cat_education_id = 'xx'; // category id for "education"
    $cat_dog_id = 'yy'; // category id for "dog"
    if ( is_category() && ( is_category( $cat_education_id ) || is_category( $cat_dog_id ) ) ) {
         wp_enqueue_script( 'my-js', 'filename.js', false );
    }
}

add_action( 'wp_enqueue_scripts', 'category_enqueue_script' );
  • 1
    This answer is totally off-topic. Your code shows how to enqueue a script, but that´s probably not what the poster wanted to ask for. Besides that your code is not very good, do you want to make 20 && operators, if you have 20 categories/posts/whatevers? – flomei Feb 8 '16 at 8:03
  • If your answer answeres the question, there are much better ways to achieve that. As @flomei stated, if you have 20 categories under news, will you run twenty conditional checks – Pieter Goosen Feb 8 '16 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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