With WordPress, calling site_url()
returns the full site URL (http://www.example.com
)
What I’m trying to do is adding something (add-something-here
) at the end of the URL with filter.
The result I’m expecting is:
http://www.example.com/add-something-here
Does someone know how to do that with filter?
I tried the following with no success:
function custom_site_url($url) {
return get_site_url('/add-something-here');
}
add_filter('site_url', 'custom_site_url');
The problem is that you are producing a loop with this filter. The function
get_site_url
is exactly where the filtersite_url
is being called.You need:
Bear in mind, that this may produce errors for scripts that rely on the real URL.
Untested, but since it’s PHP could you just try…
Untested, but this is a snippet of what I use often:
or you might simply want to get the page ID instead and it’s much better.