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.

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.