lazy load background images – Genesis theme
-
I am using a Genesis child theme, and I would like to lazy load background images, specifically for custom widgetized areas, but I’m having trouble understanding exactly how to do that.
I have read that I need to enable “Lazy Load background images”
and also add the attribute “data-bg” with a value of path to the image to elements with a background image.However, I’m not sure exactly where to add the attribute and url for my custom widgetized areas.
These custom widgetized areas have been added via my functions.php file, for example:
// Our Process page: After Header Widget Area -jlr genesis_register_sidebar( array( 'id' => 'custom-widget-process', 'name' => __( 'Custom Top Widget - Process', 'agency' ), 'description' => __( 'Custom Top Widget - Our Process page', 'agency' ), ) ); add_action( 'genesis_after_header', 'process_page_widget' ); function process_page_widget() { if (is_page('our-process')) { genesis_widget_area( 'custom-widget-process', array( 'before' => '<div class="custom-widget widget-area" id="top-section"><div class="wrap">', 'after' => '</div></div>', ) ); } }
The background image is in my child theme’s images folder, and I have styled the custom widget to use the background image via the child theme style.css:
body.ourprocess-page div#top-section {background: url(images/widget-bg3.jpg) 50% no-repeat;}
I tried adding data-bg=”[my absolute path to bg image]” to the div in my functions.php file and then removing the background image from my stylesheet but that did not work – no bg image was loaded.
How can I get the bg image to lazy load using genesis?
Thanks in advance.
- The topic ‘lazy load background images – Genesis theme’ is closed to new replies.