WordPress.org

Ready to get started?Download WordPress

Ideas

Exclude a class from post_class()

  1. davidgarlitz
    Member

    The new post_class() function is great, but it could be improved greatly by creating a way to easily remove one or more classes :

    e.g. : post_class('-post,-hentry')

    for example, to get all of the category and tag outputs but not the classes 'post' and 'hentry.'

    Wouldn't that be great?

    Dave

    Posted: 5 years ago #
  2. freesouldesign
    Member

    12345

    Couldn't agree more!

    Posted: 4 years ago #
  3. Mark / t31os
    Moderator

    12345

    Why would you need to remove a few classes though, can you not simply ignore the ones you don't need?

    CSS provides enough specific selectors to be able to selectively target what you do and don't want.

    Can you provide an example of where having a few too many classes on that element causes a problem?

    NOTE: There is currently a filter called post_class that allows the list of classes to be filtered in 2.9+ ... i've not checked earlier versions, so the ability to remove classes does now exist already.

    Posted: 4 years ago #
  4. smart card
    Member

    I searched for the Post_class filter, but I was not able to find it. Could you be more specific as to where that would be. I would look around here for some more to see if I could get a clue about any of it.

    Posted: 3 years ago #
  5. GATEKeeper
    Member

    Have to agree, it would be incredibly helpful to be able to exclude some values from the post_class output.

    I have a lot of tags in some articles, so it just makes for ugly code if nothing else, and there's no reason those tags should be showing if I'm not going to use them.

    Posted: 3 years ago #
  6. I need to figure out how to do this too. It seems the 'hentry' class is screwing up the HTML5 microdata I am adding into my theme for Google Rich Snippets. Anyone have a code example for removing a class using the post_class filter?

    Posted: 3 years ago #
  7. syso
    Member

    12345

    I'm also having the same problem. I want to use microdata for my recipes site and 'hentry' is crashing google rich snippets validator.

    Posted: 3 years ago #
  8. subsist
    Member

    You can find the filter in wp-includes/post-template.php

    Then just remove what you don't want to be automatically added.

    Posted: 3 years ago #
  9. ginecomastia
    Member

    I need to figure out how to do this too. I'm also having the same problem. Im searching for a code example for removing a class using the post_class filter?

    Posted: 3 years ago #
  10. Adam Capriola
    Member

    Here ya go:

    function remove_hentry( $classes ) {
    
    	$classes = array_diff($classes, array('hentry'));	
    
    	return $classes;
    }

    You can add more classes that you want to remove to array('hentry') if you want.

    Posted: 3 years ago #

RSS feed for this topic

Reply »

You must log in to post.

  • Rating

    12345
    12 Votes
  • Status

    This idea has been implemented