Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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}

share|improve this answer
    
That fixed it. Thanks! –  Dave Ward Nov 8 '10 at 5:34
    
Good analysis Russell! Thanks for sharing! –  hakre Dec 27 '10 at 1:03

protected by toscho Aug 24 '13 at 8:12

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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