As the backend engineering lead for BudgetTechIndia, I’m constantly looking for ways to improve our content delivery and SEO performance. One area that frequently comes up is internal linking. For a long time, our internal linking strategy was, frankly, broken. It was a classic example of a system that sounded good on paper but failed in practice.
The Problem: Random Category Links
Our content pipeline was designed to include internal links, but the implementation was flawed. Every article, regardless of its topic, concluded with a single link to a randomly chosen category page. The logic looked something like this:
const INTERNAL_LINKS = [
{ text: "budget smartphone picks", path: "/category/smartphones" },
{ text: "AI and tech innovation", path: "/category/ai-innovation" },
{ text: "tech buying guides", path: "/category/tech-guides" },
];
const pick = INTERNAL_LINKS[Math.floor(Math.random() * INTERNAL_LINKS.length)];
The result of this random selection was a complete disconnect. A detailed review of a new laptop might end up linking to our “AI and tech innovation” category, while a smartphone comparison could link to generic “tech buying guides.” The links were irrelevant to the article’s content, the anchor text was generic and unhelpful, and critically, no meaningful topical clusters were formed across our site. This approach did little to help our readers or search engines understand the depth and breadth of our content on specific subjects.
Why Category Archive Links Are Insufficient
Relying solely on category archive links for internal linking is a shallow strategy. While category pages serve an important purpose by organizing content, linking directly to them from individual posts doesn’t effectively connect related articles to each other. For internal linking to genuinely aid SEO and user experience, a more nuanced approach is required. Effective internal linking needs:
- Post-to-post links: Connecting related articles directly, rather than just pointing to a broad category page.
- Natural anchor text: Using the linked article’s actual title or a contextual phrase that accurately describes the destination content.
- Topical relevance: Ensuring that linked articles share keywords or subject matter, making the connection logical and valuable.
- Cluster formation: Building networks of highly related content within a specific topic, signaling to search engines that we are an authority on that subject.
The Solution: Contextual Post-to-Post Linking
To address these shortcomings, I replaced our random category linker with a new function I developed: buildContextualInternalLinks(). This system was designed to intelligently identify and link to truly related articles, focusing on relevance and user value.
The buildContextualInternalLinks() function operates through several key steps:
- It first fetches a pool of recent published posts from our WordPress site.
- It then filters this pool to prioritize posts belonging to the same category as the current article. This ensures an initial layer of topical relevance.
- Next, it scores each filtered post based on the keyword overlap between its title and the current article’s title. This is where the real contextual magic happens.
- Based on these scores, it selects the top 2-3 most relevant posts.
- Finally, it generates natural anchor text for these links, using the actual titles of the linked posts.
Here’s a look at the core logic of the function:
function buildContextualInternalLinks(recentPosts, { categoryId, keyword, title, maxLinks = 3 }) {
const pool = recentPosts
.filter(p => p?.slug && p?.link && p?.title?.rendered)
.filter(p => categoryId && (p.categories || []).includes(categoryId));
const keywordWords = keyword.toLowerCase().split(/\s+/).filter(w => w.length > 3);
const scored = pool.map(p => {
const pTitle = p.title.rendered.replace(/<[^>]+>/g, "").toLowerCase();
let score = 0;
for (const kw of keywordWords) {
if (pTitle.includes(kw)) score += 2;
}
if (categoryId && (p.categories || []).includes(categoryId)) score += 1;
return { post: p, score };
})
.filter(s => s.score > 0)
.sort((a, b) => b.score - a.score)
.slice(0, maxLinks);
// Build <ul> with natural anchor text from post titles
}
After the relevant posts are identified and scored, the final step (indicated by the comment in the code) involves constructing an unordered list (<ul>) of these posts, with each list item containing a link (<a>) where the anchor text is derived directly from the linked post’s title. This ensures the anchor text is always natural and descriptive.
How It Works in Practice
Let’s consider an article about "best phone under 10000 with NFC." With the new system in place, the process unfolds as follows:
- The system first identifies all other published posts that are also in the "Smartphones" category.
- It then scores these posts based on how many of the key terms from the current article’s title ("phone," "10000," "NFC") appear in their own titles.
- Based on these relevance scores, it selects the top 3 most relevant posts. For example, it might pick articles titled "Best phone under 10000 with 8GB RAM" and "Samsung M15 5G vs Redmi 13 5G."
- Finally, it inserts a "Related articles" section at the end of the current post, featuring links that use these actual post titles as their anchor text.
This approach transforms our internal linking. Instead of random, irrelevant connections, we now create robust topical clusters. All articles related to "phone under 10000" intelligently link to each other, forming a cohesive network that clearly signals to Google and our readers that we have comprehensive coverage on this specific topic.
Fallback Behavior
I also built in crucial fallback logic. If, after filtering, there are fewer than two posts in the same category that meet the relevance criteria, the system broadens its search to include all recent posts, regardless of category. This provides a second chance to find relevant content. However, if even after this broader search there are still fewer than two genuinely relevant posts found, the system simply returns an empty string. It does not force irrelevant links. This is a significant improvement over the old approach, where an irrelevant link to a random category was always forced, regardless of content context. I believe an article with no internal links is far better than one with misleading or unhelpful ones.
What I Would Check First Next Time
This experience fundamentally changed how I approach internal linking. Moving forward, when designing or implementing internal linking strategies, I will always verify the following:
- Relevance through keyword overlap: I will ensure that linked posts are genuinely relevant by checking for significant keyword overlap with the source article’s title and content, not just relying on broad category membership.
- Natural anchor text: I will prioritize using the linked post’s actual title as anchor text, or a closely related contextual phrase, rather than generic calls to action like "read more" or "click here."
- No forced links: I will never force internal links when no truly relevant content exists. An orphan post, in my view, is preferable to one that includes misleading or unhelpful links that degrade user experience and dilute SEO value.
Related
- WordPress REST API won’t set AIOSEO custom SEO metadata
- My WordPress robots.txt was different from What I expected – Here how I found the problem




