Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Copa WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Como desativar páginas de anexos de imagens no WordPress

Nota editorial: Ganhamos uma comissão de links de parceiros no WPBeginner. As comissões não afetam as opiniões ou avaliações de nossos editores. Saiba mais sobre Processo editorial.

Deseja desativar as páginas de anexo de imagem no WordPress?

As páginas de anexos de imagens geralmente parecem incompletas e, se um visitante as visualiza, isso pode deixar uma impressão ruim. Muitos visitantes simplesmente vão embora em vez de tentar encontrar o anexo em si ou a postagem principal.

Neste artigo, mostraremos como desativar as páginas de anexos de imagens no WordPress e redirecioná-las para a postagem principal.

How to Disable Image Attachment Pages in WordPress

Por que você deve desativar as páginas de anexos de imagens no WordPress?

Por padrão, o WordPress cria uma única página para cada anexo de mídia que você tem em seu site. Isso inclui imagens, arquivos de áudio e vídeo, PDFs e muito mais.

Alguns usuários podem achar essa funcionalidade útil, mas a maioria dos sites WordPress não precisa dela.

Por exemplo, os fotógrafos podem considerar úteis as páginas de anexos. Um tema de fotografia poderia usar a página de anexos para exibir dados EXIF. Isso poderia mostrar o modelo da câmera usada, as configurações da câmera e até mesmo os dados de localização da imagem.

Muitos proprietários de blogs do WordPress vinculam acidentalmente suas imagens às páginas de anexos em vez de à própria imagem, ou não gostam da aparência porque muitos temas não têm modelos especiais para as páginas de anexos de imagens.

Às vezes, uma imagem em seu site pode se tornar popular, e as pessoas podem começar a acessar a página do anexo diretamente do Google. O ideal é que os visitantes acessem sua postagem e vejam a imagem no contexto em que você a usou.

Para ajudar a resolver esse problema, mostraremos duas maneiras diferentes de desativar as páginas de anexo de imagem no WordPress para que você possa escolher a melhor para você:

Método 1: Desativar páginas de anexos de imagens no WordPress (com um plug-in)

A maneira mais fácil de desativar as páginas de anexos de imagens é usar o All in One SEO (AIOSEO). É o melhor plug-in de SEO para WordPress, usado por mais de 3 milhões de sites.

A primeira coisa que você precisará fazer é instalar e ativar o plug-in gratuito All in One SEO. Para fazer isso, consulte nosso guia sobre como instalar um plug-in do WordPress.

Depois que o plug-in for instalado e ativado, você terá um novo item de menu chamado “All in One SEO”.

Navegue até All in One SEO ” Search Appearance (Aparência de pesquisa). Em seguida, clique na guia de navegação “Image SEO”.

All in One SEO search appearance media setting

A primeira configuração é “Redirecionar URLs de anexos”. Você pode desativar totalmente a configuração ou redirecionar para a página do anexo ou para a página principal do anexo.

Recomendamos redirecionar para a página “Attachment Parent”. Dessa forma, quando um usuário acessar a página do anexo de imagem, ele será redirecionado para o seu artigo.

Observação: Se uma mídia ou imagem não tiver uma página principal, o que significa que não foi carregada em um post ou uma página, o AIOSEO exibirá a página de anexo da imagem.

Depois de selecionar sua configuração preferida, basta clicar em “Save Changes” (Salvar alterações) antes de sair da tela.

Método 2: Desativar páginas de anexos de imagens no WordPress (com um snippet de código)

Outra opção é adicionar um trecho de código ao WordPress. Não recomendamos editar seus arquivos do WordPress diretamente, portanto, usaremos o WPCode para este tutorial.

Para começar, você precisará instalar o plug-in gratuito WPCode. Para obter mais detalhes, consulte nosso guia sobre como instalar um plug-in do WordPress.

Após a ativação, você precisará acessar Code Snippets ” Add Snippet em seu painel de administração.

Em seguida, basta digitar “attachment” (anexo) no campo de pesquisa. Um snippet intitulado “Disable Attachment Pages” (Desativar páginas de anexos) deve aparecer à direita.

Quando você passar o mouse sobre ele, clique no botão “Use Snippet”.

Using WPCode search to remove attachment pages

Você será levado à página “Edit Snippet” (Editar snippet), na qual todas as configurações são definidas automaticamente para você.

Tudo o que você precisa fazer é alternar a chave para “Active” (Ativo) e clicar no botão “Update” (Atualizar).

Clicking the toggle to activate a code snippet in WPCode before hitting update

Agora, quando um usuário acessar a página de anexo da imagem, ele será redirecionado para a publicação principal. Se não houver uma publicação principal para a imagem, o usuário será redirecionado para a página inicial do site.

Esperamos que este artigo tenha ajudado você a desativar as páginas de anexo de imagem no WordPress. Talvez você também queira ver nosso guia para iniciantes sobre SEO de imagens e nosso guia sobre como corrigir problemas comuns de imagens no WordPress.

Se você gostou deste artigo, inscreva-se em nosso canal do YouTube para receber tutoriais em vídeo sobre o WordPress. Você também pode nos encontrar no Twitter e no Facebook.

Divulgação: Nosso conteúdo é apoiado pelo leitor. Isso significa que, se você clicar em alguns de nossos links, poderemos receber uma comissão. Veja como o WPBeginner é financiado, por que isso é importante e como você pode nos apoiar. Aqui está nosso processo editorial.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

O kit de ferramentas definitivo WordPress

Obtenha acesso GRATUITO ao nosso kit de ferramentas - uma coleção de produtos e recursos relacionados ao WordPress que todo profissional deve ter!

Reader Interactions

71 ComentáriosDeixe uma resposta

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Mrteesurez says

    I want to ask if the image attachment page affect SEO in the sense that some page like tags and some taxonomies are showing on Google with no contents.
    This makes search engine thinks the blog has little contents on his blog ?

    • WPBeginner Support says

      It can affect SEO, if you are not specifically using the attachment pages for some reason then we would recommend disabling them.

      Administrador

  3. Matt says

    Worked perfectly! I used the code method of setting up an image.php file with the code snippet. Works perrrfect.

    • WPBeginner Support says

      We are updating our articles as fast as we are able. For the moment you may want to check under Search Appearance > Media

      Administrador

    • Dave says

      My Yoast SEO does have this option under MEDIA. It is the first option, and it says Yoast suggests YES to “Redirect attachment URLs to the attachment itself?”
      March 2021 is when I checked.

  4. Abhishek says

    i post images and link them to media file on my site
    should i disable the attachment media pages?
    if i do, will it affect seo?

    • WPBeginner Support says

      That would depend on your personal preference and if the main content of your site is images rather than posts and pages.

      Administrador

  5. Tommy says

    Thank you! For some reason I have never experienced this issue using yoast until today! One of my sites kept redirecting to the image instead of my attachment page. Wasted an hour trying to figure out if it was a function issue I had created. Turns out it was the Yoast plugin. Easy fix thank yoU!

  6. Esther Roche says

    Hi
    Yoast has now changed all the settings, they keep doing this and honestly they’re driving people mad.
    This “Redirect attachment URL to parent post” was very handy and understandable, but now it doesn’t exist.
    Instead, we have a Media tab where the instructions seem, at least for me, a bit unclear. This is the explanation they give:

    When you upload media to WordPress, it doesn’t just save the media, it creates an attachment URL for it. These attachment pages are quite empty: they contain the media item and maybe a title if you entered one. Because of that, if you never use these attachment URLs, it’s better to disable them, and redirect them to the media item itself.

    What this seems to provoke is that now Google is showing image attachment URLs in the SERPs results. But there is no option, as before, to redirect the attachment URL to the parent post. What do we do then?

    Am I not understanding correctly the use of the new Media tab? What should I do so that Google doesn’t show those attachments as results in the SERPs that are not image search? Am I not understanding correctly the use of the new Media tab? What should I do so that Google doesn’t show those attachments as results in the SERPs that are not image search? What is it that I’m getting wrong?

    H E L P!!

    • Sevda says

      Hi Esther,
      The current function in Yoast removes the attachment urls by redirecting them to the direct url of the media file (instead of to the parent post). If you are turning it on just now, it’s normal to still have attachment page urls in the index. Selecting the option would lead to the attachment urls eventually disappearing from search engines’ indexes and being replaced by the media files’ direct urls (blabla.jpg for example).
      If you want to speed up the removal of the attachment urls, you can do so in Google Search Console.

    • Amanda Formaro says

      I agree. Not only did Yoast update, but they also removed the very option you are recommending in this post (unfortunately). And now all that’s left is to redirect to the actual attachment. :(

  7. Colin says

    The link is out of date now as the permalinks can be found under Advanced on the latest version.

    Thanks anyway as I have just updated it.

  8. Jeff says

    So if we aren’t linking to these attachment pages, is there really any reason to redirect these so google doesn’t index them? The reason I ask is for videos directly uploaded, we have the transcript in the description field so google indexes that.

    If we redirect would it still index that transcript or should I leave as is?

  9. beginner says

    i was using all in one seo plugin and i found “Redirect Attachments to Post Parent:” in my seo General settings, and i mark it.

    So, is that same and worked?

  10. Michael Peters says

    Question: How can I keep WP from creating an attachment in the database?
    What I mean is that I have roughly 40k actual posts, and over 100k rows in the wp_posts table. After running a query, it seems that there is ~100k posts with post_type “attachment.” Are all of these rows necessary?

  11. Laurence Cope says

    But how do you actually disable attachment pages? This post doesn’t disable them but puts a redirect in place. We have issues where the redirects is conflicting with actual page names. We dont want any attachment pages and therefore no need for redirects.

  12. paul says

    I would like to keep the attachment pages but within the attachment pages that display the image in a bigger size to disable links to prev next and full size image as this is where they can copy images or see images that I dont want non registered users to see etc. How can we do that?

  13. Whitney says

    Oh wait, I just realized something… if I no index the media files, does that mean all my media is not indexed or just the attachment pages?

  14. Whitney says

    Is the duplicate content issue only solved if I “no index” the pages or will the 301 redirect to parent take care of that too? I’m assuming I’d need to no index them…. but just want to make sure I’m assuming right :)

  15. Muhammad Furqan says

    Hello i also disabled attachments pages in sitemap. will this technique prevents google to index images?

  16. marco says

    Great solution!
    May I add that after the modification on Yoast I had to go to Settings->Permalinks and save settings (no need to change anything).
    Your mileage may vary, this worked for me, thanks!

    • Jodi says

      I’m having the same issue and I don’t think it’s the cache. I installed the plugin mentioned and that works fine.

    • Adrian Thompson says

      I had to go to Settings > Permalinks and click Save Changes (without making any changes) in order for it to work after the Yoast setting change.

      Hope it works for you.

  17. Henry says

    A nice informative article but oh my what a misleading title!
    The post title and the last sentence (after the comma) of the first paragraph are totally off!!!

    This is NOT disabling attachment pages/nor stopping WP from creating them (as the title implies) but redirecting links to it to somewhere else, and that is something real different!

    Disabling is stopping some from to be happen, and whatever code is shown in this article (even used by named plugins) it is not stopping WP from creating these attachment pages. This article is about how to redirect , which is okay ofcourse but not as implied by the post title and article as it. Such a shame because that would be a scoop!

    • Jesse says

      Henry has pointed out an important distinction.

      I am building a site that requires members to upload sensitive/private information via registration form. We absolutely can not have these files accessible to the public and need minimize any chance that these files will be indexed and publicly visible. Preventing the creation of attachment pages would seem the way to go, but I supposed redirects would work as well. We wouldn’t want to outright disable all attachment pages as we do want some uploaded files to be indexed, however, as WP Beginner Support pointed out, these files can still be indexed if they are contained within other posts.

      Think I will try enabling the attachment page redirects via Yoast SEO plugin as well as change the default directory where registration form uploads are stored (ie. will no longer be in default ‘/uploads’ directory) and disable indexing of that directory via robots.txt.

      Thoughts?

  18. Angela says

    Hi, thanks for the info!

    What about older images which were previously indexed by Google?

    I have had the setting on in Yoast for “redirect attachments” for at least 6 months now, but my older images are still being found.

    What would anyone recommend to do with these images? It concerns me because I get some critical errors on the ahrefs tool:

    duplicate title tags
    duplicate meta descriptions

    Shall I just go and add all the tags?

  19. Simon G.Proudfoot says

    Putting the line in my image.php file worked perfectly. It was giving me a bad SEO score beforehand as the links to the images weren’t mobile friendly. This has fixed it. Thanks :)

  20. Raleigh Leslie says

    Thanks this post helped me explain to someone why you would want to redirect media attachment pages to the actual post of page containing to media. re: “Sometimes an image on your website can become popular and people might start landing on the attachment page directly from Google. Ideally you would want them to land on your post and see the image in the context you have used it.”

    Word!

  21. Catherine says

    Thank you so much for helping me solve the problem of image attachments. I inserted the code

    post_parent)); ?>
    into my image.php file and it worked like a charm.
    So will Google now de-index my attachment page url’s?

  22. ashar says

    I just checked the redirect in SEO as these things were driving me nuts. so glad I found you. thanks – best ashar

  23. Jorge Pinto says

    I tryed the code you suggest, it works with the images associated with posts os pages, but.. all the other images uploaded that are no assigned to any post, for that images your code does not work.

    • Ogier Schelvis says

      I also had this issue. The Yoast! setting seemed to be ignored. Whether or not it was cache, I like the fact about the image.php solution that you have more freedom to determine what is going to happen. I just wanted to show a 404 for example if the post parent was not set. I solved it like this:

      if($post->post_parent != 0):
      wp_redirect(get_permalink($post->post_parent));
      else:
      $wp_query->set_404();
      status_header(404);
      nocache_headers();
      include( get_query_template( ‘404’ ) );
      endif;

  24. philip says

    Hello a user called Sam posted this issue – You write “Simply check the noindex, nofollow tag for ONLY the attachment post type.” but I do not see such an option. Are you referring to the “media” section? If I click no index under media will that no index my images or attachments? I would like to no index my attachments but I don’t want to lose traffic from Google images.

    I would also like to know the answer as I have the same issue
    thanks
    philip

    • WPBeginner Support says

      Philip, no this should not affect your Google Image Search traffic as the option redirects users landing on attachment page to the parent post URL where your image is available for search engines to index.

      Administrador

  25. Sam says

    You write “Simply check the noindex, nofollow tag for ONLY the attachment post type.” but I do not see such an option. Are you referring to the “media” section? If I click no index under media will that no index my images or attachments? I would like to no index my attachments but I don’t want to lose traffic from Google images.

  26. Mark Law says

    Thanks for the heads up, I got a bit of a shock when I saw absolutely everything had been indexed, including elements of the template such as image backgrounds and so on. I’m using Yoast so it is an easy fix – I wonder though if it is worth still having pdf attachment pages indexed – I’ll look into it.

  27. Junaid Abbas says

    Is this possible to stop attachment pages to be indexed??? I do not want to redirect them to the home page. I just want to stop indexing them.

  28. Mark says

    I love the Internet, within 2 mins of discovering an issue, I had found this post and resolved the problem! Thank you wpbeginner.com

  29. Shannon says

    Will this also fix the issue with creating duplicated content where the image holds the same title as the associated post?

  30. Bruce Simmons says

    Heads up about the plugin… if you use the gallery option to present images in a post, the plugin blocks the function and clicking on an image brings the user back the thumbs index of the images.
    -Bruce

  31. Sharon Rigano says

    Thank you for this article. It has come just at the right time as I was trying to work this one out. Turns out it is a simple solution.

Deixe uma resposta

Obrigado por deixar um comentário. Lembre-se de que todos os comentários são moderados de acordo com nossos política de comentários, e seu endereço de e-mail NÃO será publicado. NÃO use palavras-chave no campo do nome. Vamos ter uma conversa pessoal e significativa.