• 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 to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Elvin

    (@ejcabquina)

    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

    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.