Title: Define ‘data-hero-candidate’ attribute
Last modified: July 7, 2021

---

# Define ‘data-hero-candidate’ attribute

 *  [deka.jayanta](https://wordpress.org/support/users/dekajayanta/)
 * (@dekajayanta)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/define-data-hero-candidate-attribute/)
 * Hi,
    For better LCP, I want to put the ‘data-hero-candidate’ attribute in the
   first article’s featured image on the homepage. The featured image of the first
   article does not have the ‘data-hero-candidate’ attribute now. I want to add 
   that.
 * If you check the logo, the ‘data-hero-candidate’ attribute is there. I want to
   add the same attribute to the above-mentioned featured image as well. How can
   I add that?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdefine-data-hero-candidate-attribute%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Support [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/define-data-hero-candidate-attribute/#post-14713614)
 * Hi there,
 * Sorry for the very late response. The ticket must’ve been lost somewhere in our
   system.
 * As for applying this:
 * This is a tricky one as there are no filters for the `<img>` element for attributes.
 * [https://github.com/tomusborne/wp-show-posts/blob/35e410d7800273fc66f211c0f80d553e95d17f83/inc/functions.php#L193](https://github.com/tomusborne/wp-show-posts/blob/35e410d7800273fc66f211c0f80d553e95d17f83/inc/functions.php#L193)
 * But you can try adding it via script placed on your site’s footer.
 * Example:
 *     ```
       <script>
       	let wpsp = document.querySelector('.wp-show-posts:nth-of-type(1)');
       	let wpsp_firstChild = wpsp.querySelector('.wp-show-posts-image:nth-of-type(1) img');
       		wpsp_firstChild .setAttribute('data-hero-candidate','');
   
       </script>
       ```
   
 * This adds data-hero-candidate attribute to the first image of the first WPSP 
   in the page.

Viewing 1 replies (of 1 total)

The topic ‘Define ‘data-hero-candidate’ attribute’ is closed to new replies.

 * ![](https://ps.w.org/wp-show-posts/assets/icon-256x256.png?rev=2846296)
 * [WP Show Posts](https://wordpress.org/plugins/wp-show-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-show-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-show-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-show-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-show-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-show-posts/reviews/)

## Tags

 * [core web vitals](https://wordpress.org/support/topic-tag/core-web-vitals/)
 * [lcp](https://wordpress.org/support/topic-tag/lcp/)

 * 1 reply
 * 2 participants
 * Last reply from: [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/define-data-hero-candidate-attribute/#post-14713614)
 * Status: not resolved