HTML5 friendly code for removing specific featured images on categories

Community Forums Forums General Discussion HTML5 friendly code for removing specific featured images on categories

This topic is: resolved

This topic contains 4 replies, has 2 voices, and was last updated by  tornado 1 year, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #55847

    tornado
    Participant
    Post count: 29

    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

    #55859

    braddalton
    Participant
    Post count: 10243

    Try 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


    #55877

    tornado
    Participant
    Post count: 29

    Hi 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.

    #55974

    braddalton
    Participant
    Post count: 10243

    I 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.


    #56135

    tornado
    Participant
    Post count: 29

    Thanks 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

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘HTML5 friendly code for removing specific featured images on categories’ is closed to new replies.