Skip to main content
WordPress Integration

WordPress Client-Side Internal Linking with JavaScript

If the Similar AI WordPress plugin does not work for your setup, you can integrate the Similar AI API using client-side JavaScript instead. Two approaches below.

1

Method 1: Using the WPCode Plugin

WPCode lets you inject custom JavaScript into your WordPress site without editing theme files. Make sure the WPCode plugin is installed and activated before proceeding.

Step 1: Add JavaScript to the WordPress Footer

Navigate to your WordPress admin dashboard and open the Headers & Footers settings in WPCode. Paste the Similar AI JavaScript snippet into the Footer section. This ensures the script loads on every page.

<!-- WPCode > Headers & Footers > Footer -->
<script src="https://api.similar.ai/your-site/internal-links.js"></script>

Step 2: Embed the Container in Your Post Editor

In the WordPress block editor, add a Custom HTML block where you want the internal links to appear. Paste the following container div:

<div id="similarai-relatedSearches"></div>

If the block editor switches back to visual mode, click the three-dot menu on the block and select Edit as HTML to re-paste the code. The JavaScript loaded in the footer will find this container and populate it with internal links automatically.

2

Method 2: Inject JavaScript via Footer Template

If you prefer not to use a plugin, you can add the script directly to your WordPress theme footer template. This gives you full control and avoids a plugin dependency.

Step 1: Open footer.php in the Theme Editor

Go to /wp-admin/theme-editor.php?file=footer.php in your WordPress admin, or navigate to Appearance > Theme File Editor and select footer.php.

Step 2: Add the JavaScript Before the Closing Body Tag

Insert the Similar AI script just before </body> in footer.php:

<!-- Add before </body> in footer.php -->
<script src="https://api.similar.ai/your-site/internal-links.js"></script>

Step 3: Place the Container Div in Your Posts

Add the target container wherever you want the links to render. You can place it inside your post template or directly in individual posts using a Custom HTML block:

<div id="similarai-relatedSearches"></div>

Once saved, the script will detect the container and populate it with relevant internal links on each page load.

Which Method Should You Use?

  • -WPCode plugin - best if you already use WPCode or want to avoid editing theme files. No risk of losing changes during theme updates.
  • -Direct footer.php - best if you use a child theme or want zero plugin overhead. Remember that theme updates may overwrite your changes unless you use a child theme.

For a Google Tag Manager approach instead of direct script injection, see the JavaScript and GTM integration guide. If you want a server-side WordPress integration, try the WordPress plugin guide first.

Frequently asked questions

What is client-side internal linking in WordPress?

Client-side internal linking uses JavaScript injected into your WordPress pages to dynamically insert internal links after the page loads in the browser. This approach lets Similar AI's Linking Agent add and update links across your store without modifying your WordPress theme or database directly.

Which two methods can I use to add Similar AI's linking script to WordPress?

You can either use the WPCode plugin to paste the JavaScript snippet into a code block, or inject the script directly into your theme's footer template file. The WPCode method is recommended for non-developers because it doesn't require editing theme files and survives theme updates.

Will client-side linking affect my WordPress site's performance?

The script is loaded asynchronously and executes after the main page content is rendered, so it has minimal impact on page load times. Similar AI's Linking Agent only targets relevant anchor text matches, keeping DOM manipulation lightweight and focused.

Do search engines crawl links inserted by JavaScript?

Modern search engines, including Googlebot, render JavaScript and can follow client-side links during indexing. However, for best results Similar AI recommends monitoring your Google Search Console crawl reports to confirm links in your specific WordPress setup are being discovered and followed.

Do I need a developer to implement client-side linking on WordPress?

The WPCode plugin method requires no coding knowledge-you simply copy the snippet provided by Similar AI and paste it into a new code snippet within the plugin. The footer template method requires basic familiarity with WordPress theme file editing, so that option is better suited to developers or technically confident store owners.

Ready to Add Internal Links to Your WordPress Site?

Similar AI generates relevant internal links that help visitors and search engines discover more of your content. Set up takes minutes.