Support » Plugin: Related YouTube Videos » Extreme Minimized Version of Related Youtube Videos for Coders

  • Resolved Dana S


    Hi again,

    I’m starting to get lost customizing all the plugins I’m using. regarding this plugin, I won’t be using all of the wonderful features it has to offer (like shortcodes, etc.), rather I will only be using the following code in my theme (hardcoded):

    /* Load the "Related YouTube Videos" API class if it does not exist yet. */
    if( !class_exists( 'RelatedYouTubeVideos_API' ) ) {
      $file = str_replace( '/', DIRECTORY_SEPARATOR, ABSPATH ) . 'lib' . DIRECTORY_SEPARATOR . 'RelatedYouTubeVidoes' . DIRECTORY_SEPARATOR . 'API.php';
      if( file_exists( $file ) ) {
        include_once $file;
    /* Only continue if the API class could be loaded properly. */
    if( class_exists( 'RelatedYouTubeVideos_API' ) ) {
      $RytvAPI  = new RelatedYouTubeVideos_API();
      /* Do your configuration */
      $data = $RytvAPI->validateConfiguration(
          'relation'  => 'postTitle',
          'max'       => '3',
          'width'     => 150,
          'height'    => 150
      /* Search YouTube. */
      $results  = $RytvAPI->searchYouTube( $data );
      /* Create your very own custom HTML */
      if( !empty( $results ) ) {
        foreach( $results as $video ) {
          $videoID    = ( isset( $video['videoID'] ) ) ? $video['videoID'] : '';
          $videoLink  = ( $videoID !== '' ) ? '' . $videoID : 'javascript:void(0);';
          echo '<a href="' . $videoLink . '"><img src="' . $videoID . '/0.jpg" alt="" width="150" height="150" /></a>' . "\n";

    I’m hoping to minimize the plugin as much as possible, so if I want to make changes (customizations like making the video thumbnails open in a lightbox, etc.), I will be able to navigate a smaller number of pages to find what code I’ll need to work with to achieve my desired results.

    So, my question is: If all I will be using is the code above in my theme, is there a drastically smaller number of files I’ll only need?

    I’m hoping you can tell me which files I’ll need to keep (or which files I can delete and still have the plugin work with the hardcoded code above).

    This request may be expecting too much from you and if so I completely understand. Regardless, I thank you again for your wonderful contribution;


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chris


    My suggestion would be to keep all the files. Even further, I would put the code snippet into an extra PHP file into your theme folder, eg ‘relatedYTVideos.php’. This file would have to start with the PHP open tag, of course <?php

    Then you can include it whenever/wherever you need to in your actual theme with a single line/call.
    include( 'relatedYTVideos.php' );

    This way, you would only have a single file to edit when you want to customize things.

    Two other things:

    I’ve found an error: You should replace the line
    $file = str_replace( '/', DIRECTORY_SEPARATOR, ABSPATH ) . 'lib' . DIRECTORY_SEPARATOR . 'RelatedYouTubeVidoes' . DIRECTORY_SEPARATOR . 'API.php';

    $file = str_replace( '/', DIRECTORY_SEPARATOR, ABSPATH . 'wp-content/plugins/related-youtube-videos/lib/RelatedYouTubeVideos/API.php' );

    And if you’ve setup the plugin and don’t use the shortcode or widget you can even deactivate the plugin and the codesnippt still works (as long as you’re not uninstalling the plugin). This might also give you a tiny little speed boost.

    Thanks for the update with the code and ” php include” suggestion. The code you provided before worked, out of curiosity, is there a reason this replacement:

    $file = str_replace( ‘/’, DIRECTORY_SEPARATOR, ABSPATH ) . ‘lib’ . DIRECTORY_SEPARATOR . ‘RelatedYouTubeVidoes’ . DIRECTORY_SEPARATOR . ‘API.php’;

    is better than this:

    $file = str_replace( ‘/’, DIRECTORY_SEPARATOR, ABSPATH . ‘wp-content/plugins/related-youtube-videos/lib/RelatedYouTubeVideos/API.php’ );


    Thanks again for your helpful replies!

    Plugin Author Chris


    The path to the file was incomplete. It was missing the wp-content/plugins/related-youtube-videos/ part. So in case you would want to use this code while the plugin is deactivated, you couldn’t because the neccessary files could not be loaded.

    The different notation is just to make it look nicer/cleaner.

    ok, I didn’t make the connection with using the code while the plugin was deactivated…The path replacement makes sense now. Thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Extreme Minimized Version of Related Youtube Videos for Coders’ is closed to new replies.