I have:
<?php previous_posts_link(' '); ?>
-> <a href="http://example.com/path"> </a>
I need:
<?php previous_posts_link(' '); ?>
-> <a href="/path"> </a>
Wordpress by default uses absolute URLs.
You can create a filter that hooks to get_pagenum_link
and change the link:
add_filter('get_pagenum_link', function($url) {
$base = 'http://example.com/';
if (0 === strpos($url, $base)) {
$url = '/'.substr($url, strlen($base));
}
return $url;
});
Alternatively you can, by using an output buffer, catch the whole pages output and change links according to your needs inside the buffer. DOMDocument
and DOMXPath
are helpful here. Another helpful library is Net_URL2
, useful functions are parse_url
and http_build_url
.