0

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.

closed as off-topic by Mark Kaplun, bueltge, Jacob Peattie, Christine Cooper, Nathan Johnson Feb 6 '18 at 1:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2

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:

add_filter('wpseo_metadesc','custom_meta');
function custom_meta( $desc ){

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

    return $desc;
}
add_filter('wpseo_title','custom_title');
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 '18 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 – Temani Afif Jan 29 '18 at 10:44

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