Override WordPress All in One SEO Pack Plugin on Certain Pages

September 26th, 2013 - Posted by Steve Marks to PHP, SEO, Web Development.

If you use WordPress on a regular basis you’ve probably heard of the All in One SEO Pack plugin. In summary it automates a lot of the SEO across your site and allows you to customise the meta properties on a per-page basis.

Today I came across a scenario where I needed to override this plugin for certain pages or posts, inparticular changing the title. Of course, you can do this within WordPress by disabling the plugin from within individual pages:

This disables the entire plugin for the page in question though. In my scenario I wanted to make the rules a little more hardcoded, only override the title, and take the option away from the user, for example, in the event that they forgot to disable it when adding a new page. I was able to achieve this adding a filter like so to my themes functions.php file:

function my_title($title) 
    global $post;
    // Check if a certain scenario is met
    if ( $post->post_parent == 22 ) 
        // Do whatever here with your title...
        $title = 'I Rock | ' . $post->post_title . ' | ' . get_bloginfo('name');
        // We can also do other things here, like remove the canonical tag, for example...	
        remove_action('wp_head', 'rel_canonical');
    return $title;
add_filter('aioseop_title', 'my_title', 1);

As you can see, we’re plugging into the aioseop_title filter and calling our own function called my_title. This checks if the current page/post parent is set to 22 and, if so, sets the title to something specific.

This entry was posted on Thursday, September 26th, 2013 at 10:36 am by +Steve Marks and is filed under PHP, SEO, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (2)
  1. Actually – your post has put me on the path to success. That end bit is wpseo_title (string), and see the API:

  2. This sounds perfect but it does not work for me!
    Guessing the last line is wrong and that function no longer exists?