# Anchor Fragments (Hash URLs) Best Practices

**Last Updated:** 2026-01-20

## Overview

Anchor fragments (hash URLs like `/page#section`) are common in table of contents and internal navigation. This guide explains how Google handles them and best practices for SEO.

## What Google Does with Anchor Fragments

### ✅ Expected Behavior

1. **Google ignores fragments for indexing**
   - Fragments (`#anchor`) are client-side only
   - Google treats `/page#section1` and `/page#section2` as the same page
   - Only the base URL (`/page`) is indexed

2. **Anchor URLs appear in GSC Performance reports**
   - URLs with `#` may show up in Search Console
   - They get impressions but often 0 clicks
   - **This is normal and expected** - not an error

3. **Canonical tags should exclude fragments**
   - Canonical URL: `https://www.ordio.com/page/` ✅
   - Wrong: `https://www.ordio.com/page/#section` ❌

## Current Implementation

### ✅ What We're Doing Right

1. **TOC anchor links work correctly**
   - Headings have IDs generated automatically
   - Smooth scrolling to sections
   - Good UX for navigation

2. **Canonical tags exclude fragments**
   - Fixed: Canonical URLs no longer include `#anchor`
   - Base URL is canonicalized correctly

3. **Schema markup supports sections**
   - FAQ schema can include anchor links
   - Article schema supports section structure

### 📊 GSC Performance Data

**What you're seeing:**
- URLs like `/insights/ratgeber/arbeitsstunden-pro-monat/#was-muss-man-bei-arbeitsstunden-pro-monat-beachten`
- Impressions: 747, 100, etc.
- Clicks: 0

**Why this is normal:**
1. Google crawls anchor links and reports them
2. But clicks are attributed to the base URL
3. The base URL (`/insights/ratgeber/arbeitsstunden-pro-monat/`) gets the actual clicks
4. Anchor URLs showing 0 clicks is expected behavior

## Best Practices

### ✅ DO

1. **Use anchor links for TOC navigation**
   - Improves UX
   - Helps users navigate long content
   - No negative SEO impact

2. **Ensure canonical tags exclude fragments**
   ```php
   // ✅ CORRECT
   $canonical_url = 'https://www.ordio.com/page/';
   
   // ❌ WRONG
   $canonical_url = 'https://www.ordio.com/page/#section';
   ```

3. **Use descriptive anchor IDs**
   - `#was-muss-man-bei-arbeitsstunden-pro-monat-beachten` ✅
   - `#section1` ❌

4. **Link to anchor sections internally**
   - Good for UX
   - Helps users find specific content
   - No SEO downside

### ❌ DON'T

1. **Don't include fragments in canonical tags**
   - Fragments are ignored by search engines
   - Including them is incorrect

2. **Don't use fragments for content switching**
   - Don't load different content based on `#` alone
   - Use server-side routing instead

3. **Don't worry about 0 clicks on anchor URLs**
   - This is expected behavior
   - Clicks are attributed to base URL

4. **Don't try to "fix" anchor URLs in GSC**
   - They're not errors
   - No action needed

## Technical Implementation

### Canonical URL Generation

**Location:** `v2/pages/blog/post.php` and `v2/config/blog-meta-generator.php`

```php
// ✅ CORRECT: Exclude fragment from canonical URL
$url_parts = parse_url($canonical_url);
$canonical_url = ($url_parts['scheme'] ?? 'https') . '://' . 
                ($url_parts['host'] ?? 'www.ordio.com') . 
                $path . 
                (isset($url_parts['query']) ? '?' . $url_parts['query'] : '');
// Fragment explicitly excluded - canonical URLs should never include #anchor
```

### TOC Anchor Link Generation

**Location:** `v2/config/blog-template-helpers.php`

```php
// Generate URL-safe IDs for headings
function generate_heading_id($text, &$existing_ids) {
    // Converts: "Was muss man bei Arbeitsstunden pro Monat beachten?"
    // To: "was-muss-man-bei-arbeitsstunden-pro-monat-beachten"
    // Ensures uniqueness and URL safety
}
```

## Monitoring in Google Search Console

### What to Expect

1. **Anchor URLs in Performance reports**
   - Normal to see URLs with `#`
   - They show impressions but often 0 clicks
   - This is expected behavior

2. **Base URL gets the clicks**
   - Check base URL performance separately
   - Clicks are attributed to base URL, not anchor URLs

3. **No action needed**
   - Anchor URLs appearing in GSC is normal
   - No negative SEO impact
   - No need to "fix" anything

### How to Verify

1. **Check canonical tags**
   - View page source
   - Verify canonical URL excludes `#anchor`
   - Should be: `https://www.ordio.com/page/`

2. **Test anchor links**
   - Click TOC links
   - Verify smooth scrolling works
   - Check that URLs update with `#section`

3. **Monitor base URL performance**
   - Check base URL clicks/impressions in GSC
   - Anchor URLs are just reporting artifacts

## FAQ

### Q: Should I redirect anchor URLs to base URL?

**A:** No. Anchor URLs are client-side only and don't need redirects. Google already treats them as the same page.

### Q: Why do anchor URLs show 0 clicks?

**A:** Clicks are attributed to the base URL. The anchor URL impressions are just Google reporting that it saw those links, but clicks go to the base URL.

### Q: Should I add `rel="canonical"` to anchor links?

**A:** No. Canonical tags should only be in the `<head>` section, pointing to the base URL (without fragment).

### Q: Can I use anchor links for SEO?

**A:** Anchor links improve UX and can help with featured snippets, but they don't create separate indexed pages. The base URL is what gets indexed.

### Q: Should I worry about anchor URLs in GSC?

**A:** No. This is normal behavior. Focus on optimizing the base URL content and structure.

## Related Documentation

- [Canonical Tags Best Practices](./CANONICAL_TAGS_BEST_PRACTICES.md)
- [Blog TOC Best Practices](../../content/blog/TOC_BEST_PRACTICES.md)
- [Blog TOC Component](../../content/blog/components/BLOG_TOC_COMPONENT.md)

## References

- [Google: URL Structure Best Practices](https://developers.google.com/search/docs/crawling-indexing/url-structure)
- [Google Search Central: Anchor Links](https://developers.google.com/search/docs/crawling-indexing/links-crawlable)
