2

I created a separate template, attachment.php, for displaying image attachments. It's relatively simple; basically a stripped down version of single.php. Everything is working great except that when I have the All in One SEO plugin enabled (and set to rewrite titles), the titles on those attachment pages are being doubled.

For example, this attachment's title should be "11 hours of MacBook Air battery life", but the title tag is being rendered as "11 hours of MacBook Air battery life 11 hours of MacBook Air battery life"

This only happens on the attachment.php pages, not on the rest of the site's normal posts and pages.

Any idea what could cause that?

6

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}

Not the answer you're looking for? Browse other questions tagged or ask your own question.