Created
August 7, 2020 17:46
-
-
Save zergiocosta/6ee53d9fe8b818f279498f75110cad06 to your computer and use it in GitHub Desktop.
Make WordPress relative URLS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function make_paths_relative($buffer) { | |
$home_url = esc_url(home_url('/')); | |
$home_url_relative = wp_make_link_relative($home_url); | |
$home_url_escaped = str_replace('/', '\/', $home_url); | |
$home_url_escaped_relative = str_replace('/', '\/', $home_url_relative); | |
$buffer = str_replace($home_url, $home_url_relative, $buffer); | |
$buffer = str_replace($home_url_escaped, $home_url_escaped_relative, $buffer); | |
return $buffer; | |
} | |
function buffer_start_relative_paths() { | |
ob_start('make_paths_relative'); | |
} | |
function buffer_end_relative_paths() { | |
@ob_end_flush(); | |
} | |
add_action('registered_taxonomy', 'buffer_start_relative_paths'); | |
add_action('shutdown', 'buffer_end_relative_paths'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment