Title: Add attribute to background-image elements
Last modified: January 18, 2019

---

# Add attribute to background-image elements

 *  Resolved [Stefano Monteiro](https://wordpress.org/support/users/stemon/)
 * (@stemon)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/)
 * Hi,
 * I would like to add an attribute ‘data-bg’ to elements that contain background-
   images, such as columns. For this I edit bt_bb_column.php as such
 *     ```
       $output = '<div ' . $id_attr . ' class="' . implode( ' ', $class ) . '" ' . $style_attr . ' data-width="' . $width . '" data-bg="' . $background_image_url . '">';
       ```
   
 * I would expect this to work but it didn’t.Could you kindly point me to the right
   direction on how to accomplish that?
 * Thanks
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadd-attribute-to-background-image-elements%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [boldthemes](https://wordpress.org/support/users/boldthemes/)
 * (@boldthemes)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/#post-11103737)
 * Hi [@stemon](https://wordpress.org/support/users/stemon/),
 * Please try replacing the code from 106-121 line in bt_bb_column.php file with
   the following:
 *     ```
       $data = '';
       if ( $background_image != '' ) {
       	$background_image = wp_get_attachment_image_src( $background_image, 'full' );
       	$background_image_url = $background_image[0];
       	$el_style .= 'background-image:url(\'' . $background_image_url . '\');';
       	$data .= '' . $background_image_url . '';
       	$class[] = 'bt_bb_column_background_image';
       }
   
       $style_attr = '';
   
       if ( $el_style != '' ) {
       	$style_attr = 'style="' . esc_attr( $el_style ) . '"';
       }
   
       $data_arr = '';
   
       if ( $data != '' ) {
       	$data_arr = 'data-bg="' . esc_attr( $data ) . '"';
       }
   
       $class = apply_filters( $this->shortcode . '_class', $class, $atts );
   
       $output = '<div ' . $id_attr . ' class="' . implode( ' ', $class ) . '" ' . $style_attr . ' ' . $data_arr . ' data-width="' . esc_attr( $width ) . '">';
       ```
   
 * Please let us know if the changes work properly. Thanks!
 *  Thread Starter [Stefano Monteiro](https://wordpress.org/support/users/stemon/)
 * (@stemon)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/#post-11106059)
 * Hi, thanks for quick response and code snippet. Unfortunately, it didn’t work.
   Though no matter what I change in the `$output` variable nothing happens. I cleaned
   all cache and deactivated plugins, cloudflare etc. And nothing. I have also added
   the snippet to `bt_bb_column_inner.php`.
 *  Plugin Author [boldthemes](https://wordpress.org/support/users/boldthemes/)
 * (@boldthemes)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/#post-11111789)
 * Hi [@stemon](https://wordpress.org/support/users/stemon/),
 * Thanks for the info.
 * Since you are using our premium theme, please make sure to [contact our support team](https://boldthemes.ticksy.com/)
   for more detailed info. Thanks!
 *  Thread Starter [Stefano Monteiro](https://wordpress.org/support/users/stemon/)
 * (@stemon)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/#post-11115193)
 * It seems that my support has expired. If you want to pass it on to them. I have
   just tried on a fresh install locally and the same happens.
 *  Plugin Author [boldthemes](https://wordpress.org/support/users/boldthemes/)
 * (@boldthemes)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/#post-11115952)
 * Hi [@stemon](https://wordpress.org/support/users/stemon/),
 * Kids Club, our premium theme, used Rapid Composer which was replaced with Bold
   Builder plugin, so custom changes should be made differently than standard (previously
   written) method.
 * Unfortunately we can not provide you support on WordPress.org for our premium
   themes. If you would like you can write us on: [support@bold-themes.com](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/support@bold-themes.com?output_format=md).

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

The topic ‘Add attribute to background-image elements’ is closed to new replies.

 * ![](https://ps.w.org/bold-page-builder/assets/icon-256x256.png?rev=1573974)
 * [Bold Page Builder](https://wordpress.org/plugins/bold-page-builder/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/bold-page-builder/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/bold-page-builder/)
 * [Active Topics](https://wordpress.org/support/plugin/bold-page-builder/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bold-page-builder/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bold-page-builder/reviews/)

## Tags

 * ["background-image"](https://wordpress.org/support/topic-tag/background-image/)

 * 5 replies
 * 2 participants
 * Last reply from: [boldthemes](https://wordpress.org/support/users/boldthemes/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/add-attribute-to-background-image-elements/#post-11115952)
 * Status: resolved