This article explains how to replace the default All-in-One Video Gallery templates with your own template files, and how to create theme files for All-in-One Video Gallery custom post type.
Replacing Default Templates
Why replace default templates? Sometimes you might want to change the default layout that comes from the All-in-One Video Gallery plugin, to make it more suitable for your niche for example. You could do that directly in the All-in-One Video Gallery files, but this is highly discouraged as your changes would be overwritten when the plugin is updated. The recommended method is to use aiovg_load_template
filter instead.
Before we go into details, let’s see what template files are available in the plugin by default. The templates directory for the main plugin is all-in-one-video-gallery/public/templates.
- categories-template-grid.php – Displays categories as a thumbnail gallery. Used when categories template is “Grid”.
- categories-template-list.php – Displays categories as UL – LI lists. Used when categories template is “List”.
- category-thumbnail.php – Displays a category thumbnail.
- player.php – Displays the video player.
- search-form-template-compact.php – Displays a basic keyword-only search form with a compact design (the classic search button was replaced by a magnifying glass and added to the right corner of the search field).
- search-form-template-horizontal.php – Displays horizontal search form to search videos. Used when search form template is “Horizontal”.
- search-form-template-vertical.php – Displays vertical search form to search videos. Used when search form template is “Vertical”.
- single-video.php – Displays video details on the single video page (for example https://mysite.com/video/lorem-ipsum/).
- videos-template-classic.php – Displays videos as a thumbnail gallery. Used when videos template is “Classic”.
- video-thumbnail.php – Displays a video thumbnail. Used when thumbnail style is “Image Top Aligned”.
- video-thumbnail-image-left.php – Displays a video thumbnail. Used when thumbnail style is “Image Left Aligned”.
Using ‘aiovg_load_template’ filter
Let’s assume we want to display some additional text above Videos gallery. Inside your wp-content/plugins directory create folder ‘aiovg-custom-templates‘, inside this folder create file aiovg-custom-templates.php, inside this file we can add following code.
<?php /* * Plugin Name: AIOVG – Custom Templates * Plugin URI: https://plugins360.com * Description: This plugin replaces default All-in-One Video Gallery plugin public/templates/videos-template-classic.php file with videos-template-classic.php file inside this plugin directory. * Author: Team Plugins360 */ // Exit if accessed directly if ( ! defined( 'WPINC' ) ) { die; } function aiovg_custom_videos_template( $tpl ) { // $tpl is an absolute path to a file, for example // ../public_html/wp-content/plugins/all-in-one-video-gallery/public/templates/videos-template-classic.php $basename = basename( $tpl ); // $basename is just a filename for example videos-template-classic.php if ( 'videos-template-classic.php' == $basename ) { // return path to videos-template-classic.php file in aiovg-custom-templates directory return dirname( __FILE__ ) . '/videos-template-classic.php'; } else { return $tpl; } } add_filter( 'aiovg_load_template', 'aiovg_custom_videos_template' );
We also need to create a videos-template-classic.php file inside the aiovg-custom-templates directory. We only want to display some custom text above the video gallery and the rest of the template will stay the same. So, in the new videos-template-classic.php file, we will add our custom text and load the default videos-template-classic.php template after it. This code can look like this:
<?php printf( 'Today is %s.', date( 'Y-m-d' ) ); include AIOVG_PLUGIN_DIR . '/public/templates/videos-template-classic.php';
Now go to WordPress Admin Panel => Plugins menu, on the list find “AIOVG – Custom Templates” plugin and activate it, then refresh page with the video gallery and it should now display ‘Today is
The whole working example you can download here.
Custom Post Type Template
When displaying the video details page (aka single video page), your theme will usually use the single.php file in your current theme directory, most of the time this is fine, but sometimes you might want to add, remove or change some content specific to single video pages. The best way to do this is to go to your current theme directory (via FTP), create a file single-aiovg_videos.php, copy to it content from single.php (or page.php) file, if needed add / remove / change content and save the single-aiovg_videos.php file.
Now when loading the single video page, the single-aiovg_videos.php file will be used as a template. Using the_content filter hook, single-aiovg_videos.php will load all-in-one-video-gallery/public/templates/single-video.php file in order to display the actual video details (video, description, category, etc…).