• 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

Apply filter to all genesis featured image calls?

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 › Apply filter to all genesis featured image calls?

This topic is: not resolved

Tagged: add filter, featured image, genesis_get_image

  • This topic has 4 replies, 3 voices, and was last updated 4 years, 7 months ago by Brad Dalton.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • February 6, 2019 at 10:47 am #489351
    alex2k5
    Participant

    Looking to apply a filter to the output of genesis_get_image or genesis_do_post_image, anywhere it's used.

    Is there a snippet I can place in functions.php which will essentially let me do:

    apply_filters( 'myfilter', 'genesis_do_post_image' );

    globally in the theme?

    February 6, 2019 at 12:34 pm #489356
    Victor Font
    Moderator

    Filters don't work that way. apply_filters is only used in the code where it takes effect. To modify a filter, you have to use add_filter.

    The genesis_do_post_image function does not have any filters you can hook into. The function does 2 things only. First it retrieves the featured image. If a featured image exists, it calls genesis_markup to create the HTML markup.

    The genesis_markup function creates several context filters on-the-fly that you can hook into to change the output. The primary filter for changing markup is genesis_markup_entry-image-link_output.

    You would add this to functions.php:

    add_filter('genesis_markup_entry-image-link_output','my_featured_image', 10, 2);
    function my_featured_image( $tag, $args ) {
        //put your custom code here
        return $tag;
    }

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 6, 2019 at 12:57 pm #489357
    alex2k5
    Participant

    Thanks much. I will give it a shot.

    February 6, 2019 at 1:40 pm #489358
    alex2k5
    Participant

    OK, so I couldn't do it that way, wasn't working, but your feedback sent me on a path that did work.

    Basically looking to apply lazy load tech to the images Genesis spits out. They were not being caught by BJ Lazy Load and others because they are not in the_content, which is where they search for <img code to apply lazy load specs.

    What I did below is basically remove genesis_do_post_image, then re-add a modified version of it. The modified one is just the original, with the BJ Lazy Load filter applied before exporting genesis_markup. Working on my end.

    Would be nice if StudioPress could make this default, easier.

    remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
    add_action( 'genesis_entry_content', 'alex_genesis_do_post_image', 8 );
    
    function alex_genesis_do_post_image() {
    
    	if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) ) {
    	    $img = genesis_get_image( array(
    	      'format'  => 'html',
    	      'size'    => genesis_get_option( 'image_size' ),
    	      'context' => 'archive',
    	      'attr'    => genesis_parse_attr( 'entry-image', array() ),
    	    ) );
    
    	    $img = apply_filters( 'bj_lazy_load_html', $img );
    	
    	    if ( ! empty( $img ) ) {
    	      genesis_markup( array(
    	        'open'    => '<a %s>',
    	        'close'   => '</a>',
    	        'content' => wp_make_content_images_responsive( $img ),
    	        'context' => 'entry-image-link',
    	      ) );
    	    }
    	  }
    }
    February 7, 2019 at 3:19 am #489384
    Brad Dalton
    Participant

    Another option is to use one of the filters in genesis > lib > functions > image.php like

    genesis_pre_get_image
    genesis_get_image_default_args
    genesis_get_image
    

    Tutorials for StudioPress Themes & WooCommerce.

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

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