Using template files

Every site has a different look and feel. Reviewer tries to fit as good as possible within any theme, but many times you will have to change a couple things to have a 100% integrated layout and have everything up to your needs. Luckily you can easily modify the template files.

Each Reviewer related page you see on the front-end of the site is based on template files. Each template file can consist out of multiple template parts. Both of those can be overwritten according to your needs.

Overwriting templates

The templates are attempted to be loaded from your (child) themes directory first. That way you can copy one of the original template files to your theme and modify the contents. The templates are attempted to load in the following order:

1. /themes/{your-theme}/reviewer/{template-name}
2. /themes/{your-theme}/{template-name}
3. /plugins/reviewer/templates/{template-name}

So if you want to overwrite a template file, just copy it over from the Reviewer plugin template directory over to your theme (it is recommended to copy the in the the reviewer folder).

For example, if want to overwrite the template for the review title, you can copy the plugins/reviewer/templates/single-review/title.php file over to themes/your-theme/reviewer/single-review/title.php and it will automatically grab the template in your theme directory instead of the default Reviewer template.

What to overwrite

Overall it is recommended to overwrite as little as possible. That doesn’t mean it should hold you back from your modifications, but also don’t overwrite any template files you aren’t changing. With plugin updates there could also be template updates, if you overwrite templates without modifying them you will miss out on those changes until the templates are updated.

Hooks

The template parts are added to the template files through action hooks. If you want to add a new peace of data or want to remove something it is recommended to do so through these hooks.

Say you want to delete the title at all from your reviews. You can do so by calling the following line of code:

remove_action( 'reviewer_review_head', '\Reviewer\Functions\view_review_title', 15 );

This code can then be placed in your themes functions.php for example.

If you want to add a new peace of content to a review:

add_action( 'reviewer_review_content', 'custom_function_with_new_content' );

function custom_function_with_new_content() { ... };

You can then fill the newly created function with the content you want to add at the specified location. Of course you can change where the content should be added by changing the first argument of the add_action function in the code above.

Leave your feedback