# Fix Relative Links and Images in Feeds

> Turns relative links and image paths such as "/about/" in feed content into full URLs, so they work in feed readers and RSS emails.

- Type: PHP
- Runs: Run everywhere
- Category: [RSS Feeds](https://wpide.com/library/category/rss/)
- Tags: rss, urls, images
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/absolute-urls-in-feeds/

## Code

```php
$wpide_absolute_feed_urls = function ( $content ) {
    $base = untrailingslashit( home_url() );

    $result = preg_replace_callback( '/\s(href|src)=(["\'])(\/(?!\/)[^"\']*)\2/i', function ( $m ) use ( $base ) {
        return ' ' . $m[1] . '=' . $m[2] . esc_url( $base . $m[3] ) . $m[2];
    }, $content );

    return null === $result ? $content : $result;
};

add_filter( 'the_content_feed', $wpide_absolute_feed_urls, 40 );
add_filter( 'the_excerpt_rss', $wpide_absolute_feed_urls, 40 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Fix Relative Links and Images in Feeds" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
