XenForo: How to Remove Attachment Links for Guests

  • Thread starter CampFireJack
  • Start date
CampFireJack

CampFireJack

Active Member
  • #1
If you've got an image heavy XenForo forum, you can quickly build up links to attachments, which you really don't want. Attachment links are the epitome of thin content, especially in the case of this type of forum because each attachment link doesn't actually direct toward an image URL. It directs toward a separate page URL that displays the attachment. So basically, if you've got 1,000 attachments on your website pages, you've also got 1,000 URLs that go nowhere. Google and the other search engines crawl these URLs and oftentimes they consider them soft 404s. That's very bad in regards to SEO. Other times they don't report them, but the links surely build up in the index somewhere. It's not until the website owner see his website rankings drop dramatically that he decides to do something about it. This post is the step you need to take to remedy the situation. I'll explain exactly what you need to do.

First, go into your website admin and enter your Unregistered/Unconfirmed user group permission settings. In there, set your View Attachments to Posts to No. This is a critical step. If you make this setting and if a crawler visits one of these links, the URL will return a 403 forbidden status code. If you have any of these URLs indexed by the search engines, they'll eventually drop out and go away. The thing is, since you don't want any new URLs discovered, crawled, and indexed, and you would like to make the old, discovered ones disappear, you now need to unlink them. Here are the instructions for that.

Go into your Appearance > Templates area of your admin and make these template changes:

Code:
TEMPLATE "ATTACHMENT_MACROS"
line 56
<!-- REMOVE THUMBNAIL ATTACHMENT LINK FOR GUESTS -->
<xf:if is="$xf.visitor.user_id">
<a class="file-preview {{ $canView ? 'js-lbImage' : '' }}" href="{$attachment.direct_url}" target="_blank">
<img src="{$attachment.thumbnail_url}" alt="{$attachment.filename}"
width="{$attachment.thumbnail_width}" height="{$attachment.thumbnail_height}" loading="lazy" />
</a>
<xf:else /> 
<span class="file-preview">
<img src="{$attachment.thumbnail_url}" alt="{$attachment.filename}"
width="{$attachment.thumbnail_width}" height="{$attachment.thumbnail_height}" loading="lazy" />
</span>
</xf:if>         
<!-- REMOVE THUMBNAIL ATTACHMENT LINK FOR GUESTS -->

Code:
TEMPLATE "BB_CODE_TAG_ATTACH"
line 6
<!-- REMOVE FULL SIZE ATTACHMENT LINK FOR GUESTS -->
<xf:if is="$xf.visitor.user_id">
<a href="{{ link('full:attachments', $attachment, {'hash': $attachment.temp_hash}) }}"
target="_blank"><img src="{$attachment.thumbnail_url_full}"
class="bbImage {$alignClass}"
style="{$styleAttr}"
alt="{$alt}"
title="{$alt}"
width="{$attachment.thumbnail_width}" height="{$attachment.thumbnail_height}" loading="lazy" /></a>
<xf:else /> 
<img src="{$attachment.thumbnail_url_full}"
class="bbImage {$alignClass}"
style="{$styleAttr}"
alt="{$alt}"
title="{$alt}"
width="{$attachment.thumbnail_width}" height="{$attachment.thumbnail_height}" loading="lazy" />
</xf:if>         
<!-- REMOVE FULL SIZE ATTACHMENT LINK FOR GUESTS -->

What this code says is if there's an image in a post, whether it's a full size display or a thumbnail, and no matter if it's allowed to be viewed or not by a guest, it'll not show a link to that attachment to a guest, which includes search engine spiders. It's that simple.

If you have any questions, please ask.
 
Last edited:
Top