Support » Plugin: WP YouTube Lyte » Generate thumbnail URL in PHP

  • Resolved Bohdan Shila

    (@garpion)


    Hello! Is there any way I can create a function that generates the lyte thumbnail image URL?

    I want to rel=”preload” those images on blog posts for performance purposes so I’m looking for something like:

    add_action('wp_head', function () {
    if(is_singular('post)) { ?>
    
    <link rel="preload" src="<?php the_lyte_thumbnail_url(); ?>" as="image">
    
    <?php }
    });

    Is it possible? Thanks!

    • This topic was modified 2 years, 1 month ago by Bohdan Shila.
    • This topic was modified 2 years, 1 month ago by Bohdan Shila.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    you could hook into the lyte_match_thumburl filter?

    Thread Starter Bohdan Shila

    (@garpion)

    Thanks! I used that and that’s my final solution if someone needs it too:

    //Custom YouTube thumbnail
    add_filter('lyte_match_thumburl','lyte_my_own_thumburl');
    function lyte_my_own_thumburl($thumb) {
    	if (is_singular('post')) {
    		$thumb = get_the_post_thumbnail_url(get_the_id(), 'entry-body-size');
    	}
    	return $thumb;
    }
    
    //Preload thumbnail
    add_action('wp_head', function () {
    	if (is_singular('post')) { ?>
    		<link rel="preload" href="<?php echo get_the_post_thumbnail_url(get_the_id(), 'entry-body-size') ?>" as="image" type="image/jpg">
    	<?php }
    });
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    nice garpion ! đŸ™‚

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Generate thumbnail URL in PHP’ is closed to new replies.