Hi David,
I assume you are using a custom template (410.php) to display your 410 page – if that is the case, why don’t you edit the title directly in the template file?
Just checking that I haven’t misunderstood what you’re asking for.
Hi,
I am using a custom template (410.php), but as with most templates, the title tag is not contained in this template; the template grabs the theme’s header.php file with <?php get_header(); ?>. It is the header.php template which contains the call to wp_title().
If there were an is_410() function (similar to is_404()), we could use that to hook into wp_title(), by adding something like this to functions.php:
add_filter('wp_title', '410_title', 100);
function 410_title($title) {
if (is_410()) {
$title = 'This Page Has Been Removed';
}
return $title;
}
I hope that’s a little clearer?
Yes, I understand now.
This will be quite easy to implement – I will add it to the next release, probably in 2-3 weeks.
Hi David,
I was looking into this, and think that you can achieve this already without any changes to the plugin. The plugin fires a wp_410_response action whenever a 410 page is requested. You can hook into this to activate any 410-specific filters that you want. For example, adding this to your theme’s functions.php would do what you want:
add_action( 'wp_410_response', 'add_410_filters' );
function add_410_filters() {
add_filter( 'wp_title', '410_title', 100 );
}
function 410_title() {
// this would only ever be called for 410 pages
return 'This Page Has Been Removed';
}
I hope that helps?
That’s exactly what was needed! Thanks for giving it some thought, Samir.
For completeness, here is what I added to my functions.php (I had to rename the second function because a PHP function can’t begin with a number — I learned the hard way!):
add_action( 'wp_410_response', 'add_410_filters' );
function add_410_filters() {
add_filter( 'wp_title', 'title_410', 100 );
}
function title_410($title) {
global $sep;
if ( !isset( $sep ) || empty( $sep ) )
$sep = '-';
$title = 'Page Has Been Removed'.' '.$sep.' '.get_bloginfo('name');
return $title;
}
That does the job perfectly, thanks again Samir.