Add filter on wp_title not working with Yoast SEO plugin

For SEO purposes, in a specific template that has a list of items with pagination, I need to have different…

February 22, 2017

For SEO purposes, in a specific template that has a list of items with pagination, I need to have different urls and titles. Urls change using .../page/2/, .../page/3/ and the paging is handled with get_query_var('paged'). But Yoast SEO plugin doesn’t add automatically the number to the title so in the Google Search Console these pages are considered duplicates.
This code in the functions.php fixes the problem, the number “50” in the add_filter call refers to the priority, so this filter runs after the Yoast’s one and do the work!

function modify_title_with_pagination( $title ) {
	if(get_query_var('paged') && get_query_var('paged') > 0) {
		if ( is_page_template( 'your-template.php' )) {
			return $title . " (page ".get_query_var('paged').")";
    return $title;
add_filter( 'wp_title', 'modify_title_with_pagination', 50,2 );


I'm a software engineer, an everyday web developer and a maker. I usually build sites with PHP, within or without WordPress. I build Internet of Things with Arduino and ESP8266. I'm the founder of and and I'm actually the Chief Technical Officer of Better Days web agency.


Modify the language attribute based on category in WordPress

How to modify the language attribute in your Wordpress theme using a specific value

November 7, 2019

Clean up and optimize WordPress head tag

If you need to know how to remove RSS Feed URL’s from page head or how to remove post relational…

December 11, 2015

How to add rel=”nofollow” to links with preg_replace()

Adding rel="nofollow" to external link is a good SEO practice.

September 22, 2015

WP doesn’t send email? try this

Snippets for sending emails with Wordpress

February 8, 2020

Two post types share the same taxonomy in WordPress

Sharing a WordPress taxonomy between two post types is useful especially if you want to create a relation between different…

November 14, 2019

WordPress Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

How I've beat the php mysterious fatal error unknown in Wordpress caused by caching plugin WP Fastest Cache

November 7, 2019