• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Why is my if (!in_category) statement not working?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Why is my if (!in_category) statement not working?

This topic is: not resolved
  • This topic has 6 replies, 2 voices, and was last updated 13 years, 8 months ago by brightlaunch.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • February 18, 2013 at 7:30 am #20976
    brightlaunch
    Member

    I want to remove the filter amd_zlrecipe_process_head everywhere except from posts in the listed categories... but it doesn't remove it anywhere... what am I missing?

    If I just add remove_filter('wp_head', 'amd_zlrecipe_process_head'); then it is removed everywhere - so I know the problem is with the if-statement.

    if ( !in_category (array ('11','284','285','288','289','291','292','293','294','295','296','270','273','274','275','279','280','282','283')) ) {
    remove_filter('wp_head', 'amd_zlrecipe_process_head');
    }

    February 18, 2013 at 7:44 am #20982
    cdils
    Participant

    Your if statement needs to be associated with an action or filter. Try something like this instead:

    add_action('wp_head', 'custom_show_zlrecipe')

    function custom_show_zlrecipe() {

    if (!in_category() {

    remove_filter('wp_head', 'amd_zlrecipe_process_head');

    }

    }

    That code is untested, so try at your own risk. 🙂


    Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂

    I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.

    February 18, 2013 at 8:33 am #20987
    brightlaunch
    Member

    add_action('wp_print_styles', 'custom_show_zlrecipe');
    function custom_show_zlrecipe() {
    if (!in_category (array ('11','284','285','288','289','291','292','293','294','295','296','270','273','274','275','279','280','282','283'))) {
    remove_filter('wp_head', 'amd_zlrecipe_process_head');
    }
    }

    accomplished most of what I needed. But, the scripts still show up on those category pages itself... I only want it to show for the posts in those categories...

    February 18, 2013 at 8:34 am #20988
    cdils
    Participant

    Missing a semi-colon at the end of the first line:

    add_action('wp_print_styles', 'custom_show_zlrecipe');


    Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂

    I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.

    February 18, 2013 at 8:43 am #20989
    brightlaunch
    Member

    Thanks cdils... I realized the missing colon! Just revised my post... it's mostly working, but the scripts still show up on the category pages itself… I only want it to show for the posts in those categories…

    February 18, 2013 at 9:16 am #20996
    cdils
    Participant

    You might need to check usage between is_category vs in_category (http://codex.wordpress.org/Conditional_Tags)

    For instance,  you don't want it to show if it is_category('category-id) && if it's in_category('post-id').


    Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂

    I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.

    February 18, 2013 at 10:21 am #21014
    brightlaunch
    Member

    Ok, I figured it out.... needed || instead of &&:

    add_action('wp_print_styles', 'custom_show_zlrecipe');
    function custom_show_zlrecipe() {
    if (is_category() || !in_category (array ('11','284','285','288','289','291','292','293','294','295','296','270','273','274','275','279','280','282','283'))) {
    remove_filter('wp_head', 'amd_zlrecipe_process_head');
    }
    }

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble