Snippet – How to fix title duplication in Timber Site

Timber uses Twig template engine for maintaining all the view files inside of WordPress theme. For specifying the title of each page, by default, we'd something like this:

Timber uses Twig template engine for maintaining all the view files inside of WordPress theme. For specifying the title of each page, by default, we’d something like this:

{% if wp_title %}
    {{ wp_title }} - {{ site.name }}
{% else %}
    {{ site.name }}
{% endif %}

This will do the trick but in some cases, when you’re using some SEO plugin alongside, you may notice the duplication of titles in the source. If so, here’s a quick fix for the issue.

{% if wp_title %}
    {{ fn('wp_title','') }} - {{ site.name }}
{% else %}
    {{ site.name }}
{% endif %}

For vanilla WordPress, it would be something like this:

<title> <?php wp_title(''); ?> </title>

Try it out and let us know in the comments section below if this trick fixed your issue of title duplication.

Follow us on Twitter.