How to add new categories with list video

Hi, I need to add more than 1 categorie with a list of videos into the plugin. The fact is we use our own videos and in spanish language, so, we can't use the integrated videos.
Into the plugin we saw a document with a snippet to add our videos

These is the code snippet:

<?php

add_filter('wpmudev_vids_list', function( $video_list ) {
$video_list[ 'myvid' ] = 'My Favorite Vid';
return $video_list;
});

add_filter('wpmudev_vids_categories', function( $video_cats ) {
//add to other category
$video_cats[ 'other' ][ 'list' ][] = 'myvid';

//create my own category
$video_cats['mine'] = array(
'name' => 'My Category',
'list' => array( 'myvid' )
);

return $video_cats;
});

add_filter('wpmudev_vids_embed_html', function( $video_html, $slug ) {
if ( 'myvid' == $slug ) {
$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
}

return $video_html;
}, 10, 2);

?>

Adding this via a plugin, create a new categorie and one video inside.
We need to add more videos into the new categorie and also add new categories with a list of videos.

How can we do this using the above code snippet?

Thanks in advance

  • Adam Czajczyk

    Hello Jaime,

    I hope you're well today and thank you for your question!

    I modified the code a bit for you. Take a look below please:

    <?php
    
    add_filter('wpmudev_vids_list', function( $video_list ) {
    
    // creat a list of video slugs (unique, inside square brackets)
    // and titles (after = sign) for your videos	
    
    $video_list[ 'firstvid' ] = 'Vid 1';
    $video_list[ 'secondvid' ] = 'Vid 2';
    $video_list[ 'thirdvid' ] = 'Vid 3';
    
    $video_list[ 'fourthvid' ] = 'Vid 4';
    $video_list[ 'fifthvid' ] = 'Vid 5';
    $video_list[ 'sixthvid' ] = 'Vid 6';
    
    $video_list[ 'seventhvid' ] = 'Vid 7';
    $video_list[ 'eighthvid' ] = 'Vid 8';
    $video_list[ 'ninethvid' ] = 'Vid 9';
    
    // you can add here more entries just like those above
    
    return $video_list;
    });
    
    add_filter('wpmudev_vids_categories', function( $video_cats ) {
    //add to other category
    $video_cats[ 'other' ][ 'list' ][] = 'firstcat';
    $video_cats[ 'other' ][ 'list' ][] = 'secondcat';
    $video_cats[ 'other' ][ 'list' ][] = 'thirdcat';
    
    //create own categories
    $video_cats['firstcat'] = array(
    'name' => 'First Category',
    'list' => array( 'firstvid','secondvid','thirdvid')
    );
    $video_cats['secondcat'] = array(
    'name' => 'Second Category',
    'list' => array( 'fourthvid', 'fifthvid', 'sixthvid' )
    );
    $video_cats['thirdcat'] = array(
    'name' => 'Third Category',
    'list' => array( 'seventhvid', 'eighthvid', 'ninethvid' )
    );
    
    // again, you can create more categories by adding more entries
    // like those above
    // array() part assignes videos to categories (videos created
    // at the beginning of the code)
    
    return $video_cats;
    });
    
    add_filter('wpmudev_vids_embed_html', function( $video_html, $slug ) {
    
    	// finally, put all the video embed codes below using selected slugs
    	// the code will decide which one to use based on slug. 
    
    	switch ($slug) {
    		case 'firstvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'secondvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'thirdvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'fourthvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'fifthvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'sixthvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'seventhvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'eighthvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    		case 'ninethvid':
    			$video_html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    			break;
    	}
    
    return $video_html;
    }, 10, 2);
    
    ?>

    I also added some comments there so hopefully this is now pretty self explanatory and you should be able to easily add more categories and videos there. I currently created three categories, each including three videos.

    You will notice that the same video is showing for each entry but that's only because I used the same video embed code for each and you may easily replace them with your own.

    I hope that helps!
    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.