How to setup canonical URLs in XenForo

XFtoWP 1.1 now supports setting canonical URLs on your XenForo forum upon new thread creation from the WP admin. This short guide shows you the one time setup process to fully enable this feature across both websites.

Step 1: Enable Canonical URL setting

First go to the WP admin > XF > Thread comments > Create Thread settings panel and enable the new canonical URL option:

Enable canonical URLs from XFtoWP

Step 2: Setup Canonical URL Custom Field in XenForo

XFtoWP will connect to a custom field on your XenForo site named canonical and you will need to manually create this field for XFtoWP to find on thread creation.

From your XenForo admin panel go to Forums > Custom thread fields > Add field. Configure the settings any way you choose but ensure the Field ID is set to canonical.

Step 3: Make one minor template edit

Note: This step is subject to change if a better solution is found, but this is a very minor and safe template edit to make in any XenForo theme.

By default XenForo already sets a canonical URL on each thread so rather than adding a new tag we will make a template edit that changes the canonical URL tag when the custom field we created is filled out.

From your XenForo admin go to Appearance > Templates and search for the thread_view template.

Scroll down to line 38, or search for the following line:

arg-canonicalUrl="{{ link('canonical:threads', $thread, {'page': $page}) }}" />

and change it to:

arg-canonicalUrl="{{ $thread.custom_fields.canonical ? $thread.custom_fields.canonical : link('canonical:threads', $thread, {'page': $page}) }}" />

You can now save and exit the template.

Once these three steps are complete the canonical URL on each new thread created from WordPress will be set to the same permalink of that post.

Need help? Have any questions? Post to the XFtoWP support forums for assistance.