Template Hierarchy
Templates are loaded in the following order:- Theme directory -
/wp-content/themes/your-theme/visual-portfolio/ - Pro plugin -
/wp-content/plugins/visual-portfolio-pro/templates/(if installed) - Default plugin -
/wp-content/plugins/visual-portfolio/templates/
classes/class-templates.php:18
Template Structure
All templates are located in thetemplates/ directory:
Creating Custom Templates
Override Default Template
To override a default template, copy it to your theme’svisual-portfolio/ directory with the same structure:
Include Template Function
Use theinclude_template() function to load templates:
$template_name(string) - Template file path without .php extension$args(array) - Variables to pass to template
classes/class-templates.php:18
Template Variables
Item Templates
Item templates receive two main variables:$args - Item Data
$opts - Style Options
Portfolio Options
Portfolio wrapper templates receive:Template Filters
vpf_include_template
Filter template file path before loading:vpf_include_template_args
Modify template arguments before template loads:vpf_allowed_template_dirs
Add custom template directories (security filter):classes/class-templates.php:96
Item Parts Templates
Item parts are reusable components you can include in your custom templates:Title Template
templates/items-list/item-parts/title.php
Excerpt Template
templates/items-list/item-parts/excerpt.php
Meta Categories
templates/items-list/item-parts/meta-categories.php
Meta Author
templates/items-list/item-parts/meta-author.php
Meta Date
templates/items-list/item-parts/meta-date.php
Icon Template
templates/items-list/item-parts/icon.php
Inline Meta
templates/items-list/item-parts/inline-meta.php
Complete Custom Item Style Example
1. Register Custom Item Style
2. Create Meta Template
Location:wp-content/themes/your-theme/visual-portfolio/items-list/items-style/custom_card/meta.php
3. Create Image Template (Optional)
Location:wp-content/themes/your-theme/visual-portfolio/items-list/items-style/custom_card/image.php
4. Add Styles
Location:wp-content/themes/your-theme/visual-portfolio/items-list/items-style/custom_card/style.scss
Template Loading Workflow
- Plugin checks for template in theme directory
- If not found, checks Pro plugin directory (if installed)
- Falls back to default plugin templates directory
- Applies
vpf_include_templatefilter for custom locations - Verifies path is in allowed directories for security
- Includes the template file with extracted variables
Security Considerations
- Template paths are validated with
validate_file()to prevent path traversal - Only templates in allowed directories can be loaded
- Use
vpf_allowed_template_dirsfilter to add custom secure directories - Always escape output in templates using
esc_html(),esc_attr(), etc. - Sanitize any user input before using in templates
classes/class-templates.php:20-55
Best Practices
- Copy entire file - Always copy the complete template file, not just parts
- Maintain structure - Keep the same directory structure as the plugin
- Check for updates - Review plugin updates for template changes
- Use child theme - Create templates in child theme to preserve on parent theme updates
- Test thoroughly - Test custom templates with all layout types and item styles
- Add comments - Document your customizations for future reference
- Use template parts - Reuse built-in template parts when possible
- Follow coding standards - Use WordPress Coding Standards for PHP