WordPress.org

Ready to get started?Download WordPress

Forums

410 for WordPress
[resolved] Can wp_title be give an appropriate title? (6 posts)

  1. David Hunt
    Member
    Posted 1 year ago #

    Is there any way this plugin can hook into wp_title to customise the title tag? For example, I'd like my 410.php page to have the title "This page has been removed".

    I'm currently using Yoast's SEO for WordPress plugin, which allows you to define a title for 404.php, but not for 410.

    http://wordpress.org/extend/plugins/wp-410/

  2. solarissmoke
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. David Hunt
    Member
    Posted 1 year ago #

    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?

  4. solarissmoke
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, I understand now.

    This will be quite easy to implement - I will add it to the next release, probably in 2-3 weeks.

  5. solarissmoke
    Member
    Plugin Author

    Posted 1 year ago #

    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?

  6. David Hunt
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic