Community Forums › Forums › Archived Forums › Design Tips and Tricks › Apply filter to all genesis featured image calls?
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.
-
AuthorPosts
-
February 6, 2019 at 10:47 am #489351
alex2k5
ParticipantLooking 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 #489356Victor Font
ModeratorFilters 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 #489357alex2k5
ParticipantThanks much. I will give it a shot.
February 6, 2019 at 1:40 pm #489358alex2k5
ParticipantOK, 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 #489384Brad Dalton
ParticipantAnother 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
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.