• 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

Anyone know why this in_category code isn't 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 › Anyone know why this in_category code isn't working?

This topic is: not resolved

Tagged: category

  • This topic has 7 replies, 3 voices, and was last updated 10 years, 9 months ago by desirevo.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • February 4, 2015 at 1:47 pm #139683
    desirevo
    Member

    Hi guys,

    I'm attempting to remove the content of two specific certain categories from the index page. I've created index.php, and I'm using the following code on it:

     if (in_category (array( 'Update', 'Guides')) ) { 
     remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); 
     } 

    Is this incorrect? Is there a way of executing this that i'm missing? It's not returning any errors, it's just not having any effect.

    Apologies for not providing a live site, I'm currently working locally.

    Thanks.

    February 4, 2015 at 1:48 pm #139684
    Porter
    Participant

    Have you tried tossing an echo in there to see if it prints to the page? It MAY have something to do with needing to use front-page.php instead of index.php, though I'm not sure.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    February 4, 2015 at 1:53 pm #139685
    desirevo
    Member

    Thanks for the suggestion. How would I write that echo in order to achieve that?

    February 4, 2015 at 2:54 pm #139690
    Carlo
    Member

    Hi desirevo. Your code is way off, unfortunately! If you like, I can give you the correct code, or you could just go to your Genesis theme settings and the 'Blog Page Template' section and exclude the category IDs there.


    Comprehensive, easy to follow Genesis documentation

    February 4, 2015 at 2:55 pm #139691
    desirevo
    Member

    Hi Carlo. Sure, if you could point out what I'm doing wrong, then that'd be great. I'd just like to learn from whatever mistake I've made, and ensure I approach it correctly the next time.

    February 4, 2015 at 5:33 pm #139733
    Porter
    Participant

    As far as echo goes, you can use it print text out like so:

    echo("Testing to see if this code is read");

    That'll print the text in quotes on the page, or not, if it's not working. You can use it to print variables, or anything, which is great for debugging.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    February 6, 2015 at 3:45 am #139927
    Carlo
    Member

    Porter, I'm not sure how the echo command is relevant here.

    Desirevo, did you try the suggestion I gave you? Try that first, and if it doesn't work, you could try adding this code to your theme functions:

    
    add_filter( 'pre_get_posts', function( $query ) {
    	if ( $query->is_home() ) {
    		$query->set( 'cat', '-2,-3' );
    	}
    	return $query;
    } );

    Replace 2 and 3 with the IDs of your categories you want to exclude.

    However, I'm not 100% sure I understand which page you want to exclude the categories from, so the code might not work for you. Let me know where it gets you.


    Comprehensive, easy to follow Genesis documentation

    February 6, 2015 at 4:24 am #139931
    desirevo
    Member

    Hi Carlo, thanks for the suggestion. I think there may be a little confusion as to what I'm trying to do.

    I'm not trying to exclude a category as a whole, what I'm trying to do is exclude the entry content for specific categories from the index/home/blog page.

    For instance, let's say I have categories Apple, Banana, and Cherry.

    I want them all to appear on the index page, but I want the Apple and Banana categories to display entry content on the index page, and I don't want the Cherry category to do that.

    Does this make sense?

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 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

© 2025 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