Doubled titles when using All in One SEO with custom template

The problem is the way that All in One SEO is set up. It assumes that you always attach your media files to a post or page. Simple way is to attach them to a post or page and it will make your attachment title be “PostName AttachmentName – Blogname”.

The other way is also easy, but you have to make a change to the plugin. You open up the aioseop.class.php file, and find this chunk of code:


else if (is_attachment()) { 
                            $title = get_the_title($post->post_parent).' '.$post->post_title.' – '.get_option('blogname');
                            $header = $this->replace_title($header,$title);
        }

The problem with this setup is that it grabs the parent whether or not it is a child. If it has no parent, its parent title is its own title, hence the double title. To remedy this, we can add an if statement to check whether or not it has a parent to avoid the double title. So the code would look like this:


else if (is_attachment()) { 
                            if(get_the_title($post->post_parent) != $post->post_title) {
                                $title = get_the_title($post->post_parent).' '.$post->post_title.' – '.get_option('blogname');
                            } else {
                                $title = $post->post_title.' – '.get_option('blogname');
                            }
                            $header = $this->replace_title($header,$title);
        }

Then you just upload this to the All in One SEO plugin folder and your problem should be fixed.

Hope that helps.

{R:S}