• Resolved emilyatal

    (@emilyatal)


    I am using the override thumbnail function in lyte_helper.php. When I add a second youtube video to the website, it uses the same thumbnail. I’d like to be able to specify and tell it to use a different thumbnail or take the one from youtube.

    Is there a way to set the thumbnail use individually?

    —–
    I don’t know if it matters, but I use the shortcode.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    yes, by checking against the contents of the incoming $thumb variable (which contains the default thumbnail URL), e.g. for the youtube ID like this;

    add_filter('lyte_match_thumburl','lyte_my_own_thumburl');
    function lyte_my_own_thumburl($thumb) {
            if ( strpos($thumb,'7nuiOe8M6bw') !== false ) {
                    return "zyglado.jpg";
            } else if ( strpos($thumb,'pIMKYryXHzg') !== false ) {
                    return "jeff.jpg";
            }
    }

    hope this helps,
    frank

    Thread Starter emilyatal

    (@emilyatal)

    what if it is a playlist and not a single video? I tried putting in the playlist id, but that didn’t work.

    I ended up doing this as a workaround (the first match is the single video and the else is the playlist, but it seems a little clumsy):

     add_filter('lyte_match_thumburl','lyte_my_own_thumburl');
    function lyte_my_own_thumburl($thumb) {
    		if ( strpos($thumb,'tpubPLqImn4') !== false ) {
    			return "wp-content/uploads/2018/04/mpv-shot0001.jpg";
    		} else {
            	return "wp-content/uploads/2017/05/bananasunsetlogo.jpg";
    		}
    }
    • This reply was modified 6 years, 11 months ago by emilyatal.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    yeah, playlists … I guess, if you have the YT API activated, that the playlist thumbnail as incoming in $thumb will be set. if you add the playlist and then check on the thumbnail as being dictated by the YT API, then you could work against that?

    frank

    Thread Starter emilyatal

    (@emilyatal)

    I thought it didn’t work when I used the playlist id. Turns out I was having the “YouTube API, Got Error: 1” error that several people have mentioned recently on this support forum. I’m trying to get a working API now, and then I’ll see I can use the playlist ID to get the thumbnail.

    Thread Starter emilyatal

    (@emilyatal)

    when I put the playlist in the if statement, I just get a black background, not gray like when api is not working to get the thumbnail. Here’s the code I’m using:

      add_filter('lyte_match_thumburl','lyte_my_own_thumburl');
    function lyte_my_own_thumburl($thumb) {
    		if ( strpos($thumb,'tpubPLqImn4') !== false ) {
    			return "wp-content/uploads/2018/04/mpv-shot0001.jpg";
    		} else if ( strpos($thumb,'PLrQx-7EtYMM-tHx2N8QF-2pko-cJd5DqQ') !== false ) {
            	return "wp-content/uploads/2017/05/bananasunsetlogo.jpg";
    		}
    }
    • This reply was modified 6 years, 10 months ago by emilyatal.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Did some tests; the reason is the incoming $thumb does not come with the playlist ID, but with the ID of the video of which the thumbnail is shown (which in case of your playlist would be Knhp5PZRFa0) ??

    Thread Starter emilyatal

    (@emilyatal)

    is there a way to tell identify it as the playlist without using the $thumb? I’m worried that if I use the thumb for the specific video and then I change the order of the playlist it will not show the correct thumbnail until manually update the function.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    afraid not, the filter only has one argument (the url of the thumbnail).

    if however in wp-youtube-lyte.php on line you change

    	        /** API: filter hook to override thumbnail URL */
    		$thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl );

    into

    	        /** API: filter hook to override thumbnail URL */
    		$thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );

    then you could the 2nd parameter to distinguish between playlists & normal video’s?

    Thread Starter emilyatal

    (@emilyatal)

    I have a question before I dive into the javascript. Does a cached thumbnail load faster than a custom thumbnail? Does it matter which one I use, or will one give me better performance than the other?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    for the first request the cached thumbnail will be a bit slower (as the file has to be fetched from YT), after that -assuming filesize is similar- speed should be the same really.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Override thumbnail – multiple videos’ is closed to new replies.