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 remover automaticamente links de imagem padrão no WordPress

O WordPress facilita muito o upload de imagens e a criação de galerias de imagens. No entanto, as versões mais antigas do WordPress vinculavam automaticamente a imagem ao arquivo de mídia.

Ao longo dos anos, ouvimos muitos leitores procurando maneiras de remover esses links de imagem padrão. E a boa notícia é que existe uma solução simples.

Neste artigo, mostraremos a você como remover automaticamente os links de imagem padrão no WordPress.

Removing default image links in WordPress

Observação: O WordPress não adiciona mais links de imagem padrão quando você carrega imagens em seus posts ou páginas. No entanto, se você ainda estiver usando uma versão mais antiga ou observar esse comportamento em seu site, poderá tentar as etapas a seguir.

Por que você deve desativar os links de imagem padrão no WordPress

Por padrão, o WordPress vincula as imagens a si mesmo. Um usuário vê que a imagem é um link, clica nele e é levado ao arquivo de imagem.

A partir dessa página, o usuário tem duas opções: clicar no botão “voltar” do navegador ou ir para outro site.

Geralmente, é o último caso, o que significa que você está perdendo visitantes do site. Isso também afeta o tráfego de SEO da sua imagem porque os mecanismos de pesquisa podem redirecionar os usuários para o link usado para a imagem em vez da sua publicação.

Em geral, isso cria uma experiência ruim para o usuário e afeta a taxa de rejeição do seu site.

Uma solução é simplesmente selecionar a opção para desativar o link todas as vezes, mas isso não é viável porque às vezes você simplesmente esquece.

Removing image link

Remoção do link de imagem padrão no WordPress

É muito simples desativar o comportamento padrão de vinculação de imagens no WordPress. No entanto, você precisará adicionar algum código ao seu site WordPress. Se nunca fez isso antes, dê uma olhada no nosso guia sobre como copiar e colar trechos de código no WordPress.

Tudo o que você precisa fazer é adicionar esse trecho de código no arquivo functions.php do seu tema, em um plug-in específico do site ou em um plug-in de trechos de código.

function wpb_imagelink_setup() {
    $image_set = get_option( 'image_default_link_type' );
     
    if ($image_set !== 'none') {
        update_option('image_default_link_type', 'none');
    }
}
add_action('admin_init', 'wpb_imagelink_setup', 10);

Esse código basicamente diz ao WordPress para atualizar a opção image_default_link_type e defini-la como “none”. Essa opção é então armazenada em seu banco de dados do WordPress.

Recomendamos adicionar o snippet de código com o WPCode, o melhor plug-in de snippets de código.

WPCode Pro version

O WPCode facilita a adição de código personalizado no WordPress sem editar o arquivo functions.php do seu tema. Isso significa que você não precisa se preocupar em danificar seu site.

Ele também vem com uma biblioteca integrada de trechos de código do WordPress, lógica condicional inteligente, gerador de código e muito mais.

Primeiro, você precisará instalar e ativar o plug-in gratuito WPCode. Para obter instruções detalhadas, consulte nosso guia sobre como instalar um plug-in do WordPress.

Em seguida, vá para Code Snippets ” + Add Snippet no painel do WordPress. Em seguida, localize a opção “Add Your Custom Code (New Snippet)” (Adicionar seu código personalizado (novo snippet)) e clique no botão “Use snippet” (Usar snippet).

Add a new custom snippet in WPCode

Depois disso, você pode adicionar um título ao seu snippet de código. Ele pode ser qualquer coisa que o ajude a lembrar para que serve o código.

Em seguida, basta colar o trecho de código acima na caixa “Code Preview” (Visualização de código) e escolher “PHP Snippet” como o tipo de código no menu suspenso.

Paste code snippet in WPCode to remove default image links

Por fim, alterne a chave de “Inativo” para “Ativo” e clique no botão “Salvar snippet” na parte superior da página.

Activate and save your custom code snippet

Agora, vá em frente e adicione uma nova imagem no WordPress. Você perceberá que não há mais links para o arquivo de imagem ou para a página de anexo. Isso tornará a adição de imagens no WordPress um pouco menos incômoda, especialmente se você nunca faz links para imagens.

Se você quiser saber como adicionar links a uma imagem ou galeria de imagens, siga nosso guia sobre como adicionar links personalizados a imagens de galeria no WordPress.

Esperamos que este artigo tenha ajudado você a aprender como remover automaticamente os links de imagem padrão no WordPress. Talvez você também queira ver nosso tutorial sobre como adicionar e alinhar imagens em posts e páginas do WordPress ou conferir nossas escolhas dos melhores plug-ins do Instagram para 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

68 ComentáriosDeixe uma resposta

  1. Palla Sridhar

    I am looking for this kind of tip for my IMAGE SEO. The default image links create web image search results which have very low CTR. I used a plugin option, but still my web image search results impressions are very high.

    • WPBeginner Support

      If you mean you used a plugin to try to update the old links and they are still on search engines then that would be because search engines need to clear their cache which takes some time before the links are crawled again to remove them from search results.

      Administrador

  2. Sufian Diraneyya

    This is exactly what I was looking for. Thank you very much!

    • WPBeginner Support

      You’re welcome, glad our article was helpful :)

      Administrador

  3. Pam

    Hello, I’m a novice WP user, and I took over an established WP Pratt theme webpage. On the bottom of the page, there is a “call to action” button and this text: “This is just an example text widget. You can add text widgets here to put whatever you’d like.” I’ve searched all widget and theme info and cannot find where this came from. How do I remove it permanently? Thank you.

    • WPBeginner Support

      It would depend on the specific theme. If you know the theme’s name and reach out to the support for the theme they should be able to let you know where to modify that. Two possible locations it could be under are Appearance>Widgets and Appearance>Customize

      Administrador

      • Pam Hunter

        The WP theme is Pratt, as I mentioned. I scoured the Pratt support and could find no info. I can’t find anything that appears to show why this call to action button showed up uninvited, including in the sections you mentioned. I’ll await an answer from the Pratt support. Thanks.

  4. Lana

    This code returns an error for me. Removing the } at line 7 corrected the error.

    • WPBeginner Support

      The closing bracket on line 7 contained the code within the function. Unless you added another closing bracket that may cause issues later on.

      Administrador

  5. Cezar

    I Have Updated Yoast on one of my website from an early version of yost to the last version i did not see fro the begining that has change my image link from postes from none to attachment page and it`s showing example.com/post-title/post-title/. This is a big problem how can i change all attachment page img link to none ?

    Thank You

    • WPBeginner Support

      Hi Cezar,

      We are not quite sure that got your question right. If you want to remove the attachment links and point them to the image file itself, then you can try this.

      In Yoast SEO settings go to SEO > Search Appearance and click on the Media tab. Make sure that “Redirect attachment URLs to the attachment itself?” option is checked to Yes. Click on save changes button and then check your posts with attachments.

      Administrador

      • Cezar

        Thank you for your answer, i already did this (the dev from yoast have made a topic were appologies for the problem created also made a plugin…) but the problem remain even with that option set on yes images have that problem example.com/topic-name/topic-name/ (i can`t change manually on all topics since i have 16.000+ posts) i look for sometfing to change all image link at once from attachment/media/custom to none

        Thank you again

      • Cezar

        This code can help remove all curent links from post images ??? cause after that update most of my images gone crazy and i have 12k 404 pages on ga after a few days i updated that yoast…..

        Many thanks

  6. Benjamin

    I have Created the website, and I have created page and named it Home. But there is one more page namely home that appears in website, which is not seen in the page column in dashboard. how to remove this extra home page

    • WPBeginner Support

      Hi Benjamin,

      Most likely your theme has a built-in homepage template. Please review your theme settings or contact theme author for support they be able to help you set it up.

      Administrador

  7. Mathukutty P. V.

    Read in one blog that writing description about image and linking to attachment page is good for seo. Is it correct?

  8. Martin

    Hey there,

    Just want to mention the following. I wanted to try this to disable linking for the pages’ featured image, and so I copy/pasted the code snippet on my websites functions php page (appearance -> editor), clicked update and received this exact message “Parse error: syntax error, unexpected ‘$image_set’ (T_VARIABLE) in /home/reikibok/public_html/wp-content/themes/Avada-Child-Theme/functions.php on line 16”

    I removed the code snippet to bring it back to default settings, and the same message pops up. Any other link I click on the dashboard now leads to a blank page with this error message :-D. Thought it would be helpful to mention (would also appreciate advise on how to fix this). Thanks!

  9. suzie

    Hi
    Does the php code snippet only apply to images uploaded to wordpress gallery itself or to all images?

    i use some images hosted in flickr and pinterest and add the link to my post so clicking the image takes someone to the flickr/pinterest account – which i’m quite happy to happen.

    What about jetpack’s cdn?

    Thank you for your time

    • WPBeginner Support

      Hey Suzie,

      The code is only applied to the media upload popup which appears when you click on the Add Media button. All other images on your site will not be changed.

      Administrador

  10. Raul Canessa

    Is there any way to change the image link to none in uploaded images. My site has over 1000 posts and I do not want to do it manually.

    Thanks

    • WPBeginner Support

      If you have already added the images to your WordPress posts and pages, then you will have to manually remove the links.

      Administrador

      • Spencer

        You can also target these links with javascript to prevent the default action.

  11. Swadesh

    Hi,

    I have added this code into functions.php as per your instructions but images link URL is still running.

    Thanks
    Swadesh

  12. Sarah

    Heya, I just tried doing this and my website totally crashed. It took me forever to figure out how to adjust the functions.php file back to normal using cPanel, and then I had to recreate my child theme. Any suggestions as to how I could unlink all my images at once without using php? The No Image Link Plugin seems to be fairly old now (last updated 1 year ago).. Cheers!

  13. Marlene

    Thank you thank you thank you! I saw this post ages ago and have always been terrified to attempt any coding. Finally took the plunge and it worked like a charm! Such an amazing time saver!

  14. Patton McGinley

    I can’t even find a “Link To” option for individual images in WordPress 4.3.1. Why does WordPress insist on making the image link a default in the first place?

  15. andy

    i very really need this tutorials to remove all link that’s in images post in wordpress.
    But, i have one question, is it work for the snippet of excerpt image ? eg. in homepage / archive, thanks. i need it to my blog

  16. Owais

    Is there anyway to remove image links, those are already done? Actually, I have around 500 pages in which I have image links. So, doing manually it’ll take time. So, please tell me is there anyway I can remove image links automatically?

    Thanks

  17. D Blake

    Should adding this code & clicking the blue ‘Update file’ button at the bottom of the window make the change instantly? I have added this code & clicked ‘Update file’, but after opening my site in a new browser window (as if I was a member of the public visiting my site) – making sure I’m not logged in with WP – the images are still ‘clickable’.

    Going back to the functions.php page where I added the code, after all the existing text, the code is not there!
    Looking closely at the content of the functions.php page, it appears to just be a page of instructions. There is no coded text on this page that actually appears on my site?

    • WPBeginner Support

      Functions.php file is a place where your WordPress themes stores functions or code it need to execute. Many of these things do not directly appear on your site but they support several features of your WordPress theme.

      Try to add the code again. When you click on the blue Update button, wait for a while to see the confirmation that file edited successfully.

      This code does not make links already added to images disappear. It will however, make it possible that when you upload an image next time in WordPress posts, they are not automatically linked. To remove the links from images you will still have to edit your posts and unlink the images.

      Administrador

  18. slewjo

    Hi there, I just added this code to my functions.php file and I can’t access my site now. I removed the code and still can’t access my site. Very scared. Please help.

    • Eleni Kapousouz

      I added the code and now i cant access my site. NEED HELP HERE. What should i do?

  19. samira

    please i want to edit the gallary navigation because have downloaded a theme and have change the pictures in the gallary but if i click on the navigation button it goes to the theme website pictures not my website so i want you to help me find where i can located the gallary navigation to change it

  20. kathy

    It’s ok, all fixed, just deleted the code from file manager on cpanel,

  21. kathy

    Hello, I’ve added the code and now I can’t access my site. Can you please help me remove it. Thnaks.

  22. WPBeginner Staff

    You should paste this code at the bottom of your functions.php file. If your functions.php file has a ‘ ?> ‘ which is the closing tag for PHP, then paste the code before ‘?>’.

  23. Adam Dartez

    Man I really can’t find the answer to this question anywhere. Instead of using the media manager to handle my images I was wanting to put another folder inside my root domain, place all my images and videos inside it and then instead of uploading them from the post just link to them in that folder. For example in my root WP directory place an additional folder, say titled cdn, and if it was an image, say located at mywproot/cdn/image/imageiwanttoembed.jpg. Ive read that having a lot of image attachments pages is bad so that parts solved but would my images still be indexed by Google? Would my Yoast plugin still create a sitemap for my images? Does this even make sense? It would just be so much easier to manage as my site has a lot of images???

  24. Caroline V.

    Dear, I have I think the dumbest question.
    Where in functions.php shoud I paste the code?

    under or above something in particular?
    Or I just can paste it at line 1?

    Thanks :)

  25. Roeg

    Can this be done retroactively in bulk or do I have to go back to each image individually?

    • Alvaro

      I need to know how to do it retroactively too. Any solution? Thanks.

  26. metroholic

    Hi, what if instead of none I rather want the image to link to my post automatically? How should I go about it?

    • Rollingspoke

      Copy the URL to your post, select “Custom URL” under “Link To” and then paste the URL.

  27. Chris Pink

    Great, thank you. One more numpty possibility removed from the fingers of the user….

    A question; is it possible to do this in retrospect. ie is there a way of removing all links from all images blogwide?

  28. Zoran

    Hi, I’m a WP beginner and I used it in my child-theme functions.php and it works fine. Is there any way to apply the same in conjunction with tablepress cells containing? Any image that is inside of a tablepress cell still shows complete url. If you have any suggestions I would really appreciate it.

  29. Putranto

    Another option is to use plugin: Page Links To. This is handy for posts with featured image.
    There’s an option on every page to change the link to the target url or change to #.
    “Drawback” is, it changes not only the image link but also the post title link.

  30. Ozzy Musa

    Thanks man, it is labor intensive when I have to unlink all images I attach to a post due to Wordpress automatically linking to the images. The fact that you mentioned it also affects SEO is shocking, no wonder i have been getting little image search traffic. Most people were being taken to the image directly and not the actual pages that images are on. Almost an problem I search for on Google comes up wpbeginner.com at the very top page. Syed Balkhi should be named KING OF WORDPRESS as he has tons of valuable tips and tutorials on wordpress.

  31. Mack

    Jason is Right. This code is not working. Please check and update it.

  32. Jason

    Syed, thanks for the article. I copied and pasted your code into my functions.php file and it broke my site. Is there a syntax error in your code that you know of?

  33. Håkon Stillingen

    Thanks for this.

    I am using attachment page with navigation controls as “gallery single picture view”. In my case clicking on the image on the attachment page leads to the image file, which I want to avoid. What would the approach to avoid this, using the same principles described in this post?

    Attachment page example – http://www.stillingen.com/new-york-city/lower-manhattan-new-york-at-night/

  34. Zimbrul

    It’s a great tip as I often choose “none” for the images on the page unless I want to link them externally or they are part of a gallery.
    Will applying the code to the theme disable the other options of linking images or it’s just for the default case in which you don’t specify a different option for the image on page?

  35. Connie

    Thanks for that! I was searching for a function like that

  36. Travis Pflanz

    I have been using the following line of code to do the same thing:

    update_option(‘image_default_link_type’,’none’);

    Why/how is your code snippet better?

  37. Praveen Prasad

    Is it necessary to add Featured Image for every post?

    • Travis Pflanz

      Necessary? It all depends upon your theme/need in the website. This snippet does not deal with the featured image. It refers to images added into the doby/content of the post/page.

      • Travis Pflanz

        That’s body, doby

  38. Anand Muglikar

    A lightbox also solves this problem and is more elegant.

    • WPBeginner Support

      Yes it cvould be an alternate. But a lightbox could also cause slow page load, search engines would still redirect users to attachment pages, lastly not all people are fan of lightboxes.

      Administrador

  39. jonathanwthomas

    I would actually like it to do the opposite – ALWAYS link to the image file. I use a lightbox gallery for all image links so readers can view the full sized version. Often, I forget – or my writers forget – to select ‘link to image file’ which my lightbox requires to work.

    • Norcross

      all you’d need to do is change the option setting to ‘file’ instead of ‘none’

    • Travis Pflanz

      Just change ‘none’ to ‘file’ in the code snippet above. Tested and working.

  40. Jami Howard Mays

    Can the site owner still enable image link on a per-use basis? On occasion, a client will want to make an image-style button and flipping over to the text editor to hand code the url into the image is a little out of reach for a few of my clients.

    • E.S. Ivy

      I’m wondering this same thing! I often want the image to be a link, but I don’t like the default link to the image file.

      • Hemant Aggarwal

        Yes, this can be done while attaching the image.

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.