• Resolved mbox904

    (@mbox99)


    Hey guys i’m doing some tweaks to speed up my website website. I’m just having some troubles detecting when it’s a post and category page. What i’m doing is test if the user is not on a post,page or category page to run the code to disable the plugin’s css.

    So far i’ve tried a few options but only when they’re on a page “is_page()” that’s only when the code works. I’m still trying to figure out how to detect if its a post and categories this is my current code so far:

    function remove_scripts() {
    	if ( is_page() || is_single() ) {
         		wp_dequeue_style( 'plugin-style' );
      		wp_dequeue_script( 'plugin-js' );
    	}
    }

    I’ve also tried “is_singular(‘post’)” instead of is_single but none of both seem to work. Any ideas how to detect if it’s a post and how to detect if it’s a category page? Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • WordPress has a function is_category() that might help.

    Where exactly are you calling this function? You will have to make sure that it is hooked in such a way that it runs after the enqueue functions but before any output is shown in the browser.

    add_action() has a priority parameter that can help you with this.

    Thread Starter mbox904

    (@mbox99)

    Thanks for the answer Hassan ?? Yeah i’m calling the add_action() function. I managed to get it working by changing the logic of the “IF” statement and thanks to you i managed to get it working on the category pages. That function worked perfectly.

    Appreciated your help buddy!

    Have a good year ??

    Glad I could help ?? Happy new year!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help detecting when it's a post, page and category page’ is closed to new replies.