Skip to main content
Visual Portfolio uses a template system that allows you to override default templates in your theme or create completely custom templates.

Template Hierarchy

Templates are loaded in the following order:
  1. Theme directory - /wp-content/themes/your-theme/visual-portfolio/
  2. Pro plugin - /wp-content/plugins/visual-portfolio-pro/templates/ (if installed)
  3. Default plugin - /wp-content/plugins/visual-portfolio/templates/
Location: classes/class-templates.php:18

Template Structure

All templates are located in the templates/ directory:

Creating Custom Templates

Override Default Template

To override a default template, copy it to your theme’s visual-portfolio/ directory with the same structure:
Example - Custom Meta Template:

Include Template Function

Use the include_template() function to load templates:
Parameters:
  • $template_name (string) - Template file path without .php extension
  • $args (array) - Variables to pass to template
Example:
Location: 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):
Location: classes/class-templates.php:96

Item Parts Templates

Item parts are reusable components you can include in your custom templates:

Title Template

Location: templates/items-list/item-parts/title.php

Excerpt Template

Location: templates/items-list/item-parts/excerpt.php

Meta Categories

Location: templates/items-list/item-parts/meta-categories.php

Meta Author

Location: templates/items-list/item-parts/meta-author.php

Meta Date

Location: templates/items-list/item-parts/meta-date.php

Icon Template

Location: templates/items-list/item-parts/icon.php

Inline Meta

Location: 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

  1. Plugin checks for template in theme directory
  2. If not found, checks Pro plugin directory (if installed)
  3. Falls back to default plugin templates directory
  4. Applies vpf_include_template filter for custom locations
  5. Verifies path is in allowed directories for security
  6. 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_dirs filter to add custom secure directories
  • Always escape output in templates using esc_html(), esc_attr(), etc.
  • Sanitize any user input before using in templates
Location: classes/class-templates.php:20-55

Best Practices

  1. Copy entire file - Always copy the complete template file, not just parts
  2. Maintain structure - Keep the same directory structure as the plugin
  3. Check for updates - Review plugin updates for template changes
  4. Use child theme - Create templates in child theme to preserve on parent theme updates
  5. Test thoroughly - Test custom templates with all layout types and item styles
  6. Add comments - Document your customizations for future reference
  7. Use template parts - Reuse built-in template parts when possible
  8. Follow coding standards - Use WordPress Coding Standards for PHP

Debugging Templates

Enable WordPress debug mode to see which template files are loaded:
Add debug output to find template path: