Community Forums › Forums › Archived Forums › General Discussion › HTML5 friendly code for removing specific featured images on categories
Tagged: category, featured image, remove
- This topic has 4 replies, 2 voices, and was last updated 10 years, 7 months ago by tornado.
-
AuthorPosts
-
August 12, 2013 at 1:30 pm #55847tornadoParticipant
Hi.
I want to prevent featured images from displaying on certain categories that display on separate blog pages I have created.
I used this previously from here, but have been told that it should go in the functions.php file and NOT the Genesis page_blog.php file as stated (makes sense as the Genesis file does specifically say not to touch it).
Since my site was coded for HTML5, it does not work. Anybody got any ideas? I am not a developer so I haven't a clue (no kidding!).
add_action( 'genesis_before_post' , 'wps_no_featured_image' ); add_action( 'genesis_after_post_content' , 'wps_no_featured_image' ); /* * Remove featured image from certain posts. * * Stops featured image from displayed on the Small Group Show category (126) on * the blog page. * * @author Travis Smith * @link http://wpsmith.net/2012/genesis/how-to-hide-the-featured-image-of-a-specific-category-on-the-blog-page-in-genesis/ * * @global stdClass $post Post object. * * @return null Returns early if post is not in our chosen category. */ function wps_no_featured_image() { global $post; if (! in_category( array( 20,21,22 ) ) ) return; if ( 'genesis_before_post' == current_filter() ) remove_action( 'genesis_post_content', 'genesis_do_post_image' ); elseif ( 'genesis_after_post_content' == current_filter() ) add_action( 'genesis_before_post_content', 'genesis_do_post_image' ); }
You will note that categories 20,21 and 22 are the ones I want to prevent the featured images from showing.
Cheers.
G
August 12, 2013 at 2:24 pm #55859Brad DaltonParticipantTry changing to the new HTML 5 loop hooks for Genesis
The above code uses the old XHTML loop hooks which you can see in the chart after clicking the link.
Example:
XHTML Hook Location = genesis_before_post
The above hook has now changed to the hook below for HTML 5 enabled child themes.
HTML5 Hook Location = genesis_before_entry
August 12, 2013 at 3:31 pm #55877tornadoParticipantHi Brad.
Thanks for your reply. I can't get it to work. I had replaced the old hooks as per your link, but nothing:
add_action( 'genesis_before_entry' , 'wps_no_featured_image' ); add_action( 'genesis_entry_footer' , 'wps_no_featured_image' ); function wps_no_featured_image() { global $post; if (! in_category( array( 20,21,22 ) ) ) return; if ( 'genesis_before_entry' == current_filter() ) remove_action( 'genesis_entry_content', 'genesis_do_post_image' ); elseif ( 'genesis_entry_footer' == current_filter() ) add_action( 'genesis_before_entry_content', 'genesis_do_post_image' ); }
It's frustrating with me not understanding the code, because I don't have any more clues to go at. I've tried different variations also.
August 13, 2013 at 1:30 am #55974Brad DaltonParticipantI think if you don't understand code it may be easier to try a plugin.
I'm sure there's one for this solution in the WordPress.org repo.
August 13, 2013 at 1:09 pm #56135tornadoParticipantThanks for the reply, Brad. I think this has got me - there's nothing out there that I can find, plus I've been about 10 pages deep on more Google keywords than I can remember.
Cheers anyway.
G
-
AuthorPosts
- The topic ‘HTML5 friendly code for removing specific featured images on categories’ is closed to new replies.