• How can I automate the insertion of a code at the top of the HTML every time we upload a new article on the website?
    <link rel=”preload” href=”link to the article image” as=”image”>
    I need this because otherwise, the CSS loads before the image, and the LCP slows down in Google Insights.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Aleksandar Uro?evi?

    (@urkekg)

    Hi @leonida99,

    I suggest your developer implement a preload link to the theme header template file because the Head&Footer Code plugin cannot help with a dynamic featured image per blog post.

    Or if you don’t use a child theme, create a file wp-content/mu-plugins/preload-featured-image.php with the following content:

    <?php

    function twu_add_preload_feature_image() {
    if ( is_single() && has_post_thumbnail() ) {
    $thumb_id = get_post_thumbnail_id();
    $thumb_url = wp_get_attachment_image_url( $thumb_id, 'full' );
    echo '<link rel="preload" href="' . esc_url( $thumb_url ) . '" as="image">';
    }
    }
    add_action( 'wp_head', 'twu_add_preload_feature_image', 5 );

    Hope that works for you?

    Aleksandar

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.