# Upgrade http:// Links to Your Own Site to https://

> Rewrites old http:// links and images pointing to your own domain to https:// when content is displayed, fixing "not secure" mixed content warnings after moving to SSL without editing every post.

- Type: PHP
- Runs: Frontend only
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: https, mixed-content, links
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/content-https-links-in-content/

## Code

```php
$wpide_https_fix = function ( $content ) {
    if ( ! is_ssl() && 'https' !== wp_parse_url( home_url(), PHP_URL_SCHEME ) ) {
        return $content;
    }
    $host = wp_parse_url( home_url(), PHP_URL_HOST );
    if ( ! $host || false === stripos( $content, 'http://' . $host ) && false === stripos( $content, 'http://www.' . $host ) ) {
        return $content;
    }
    return preg_replace( '#http://((?:www\.)?' . preg_quote( preg_replace( '/^www\./', '', $host ), '#' ) . ')(?=[/"\'\s:]|$)#i', 'https://$1', $content );
};

add_filter( 'the_content', $wpide_https_fix, 99 );
add_filter( 'widget_text_content', $wpide_https_fix, 99 );
add_filter( 'widget_block_content', $wpide_https_fix, 99 );
```

## Notes

Only your own domain is changed; a database search and replace is still the permanent fix.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Upgrade http:// Links to Your Own Site to https://" 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/
