I am working on an project with many different page templates instead of custom post types. For SEO purposes I need to rewrite the title- and meta-description, which normally works on the page itself. Because of the impact of changing these titles and descriptions (1600 pages), I'd like to change the title- and meta-description templates for all pages with a custom page-template in the Yoast plugin.

Is there a way to rewrite the titles & meta's based on page template (page-[template-name].php) in the Yoast plugin?

I can use a filter to change title- and meta-description based on the php template itself, but it is not the best solution, because I'd still like to use the variables like %%sep%%, %%sitename%%, etc.

1 Answer 1


You may consider the use of both filter wpseo_metadesc (for meta description) and wpseo_title (for title). The idea is to change the values of title and/or description depending if you meet some condition.

So your code will look to somthing like this:

function custom_meta( $desc ){

    if (/* do your test here to check template or any other values*/) {
        $desc = "Change the description";

    return $desc;
function custom_title( $title ){

    if (/* do your test here to check template or any other values*/) {
        $title = "Change the title";
    return $title;

You can for example consider the function is_page_template() for your test.

  • This indeed was a solution which I founded myself partly, but I did not mentioned the filter. Is there a way to use the Yoast variables in the function?
    – Falch0n
    Jan 29, 2018 at 10:42
  • @Falch0n yes you can use them since they are not specific to Yoast .. so you can for example get the sitename using another function and the same for any other variables Jan 29, 2018 at 10:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.