Why does wp_redirect strip out %0A (url encoded new line character) and how do I make it stop?

If you take a look to the wp_sanitize_redirect() function you will notice it is removing the new lines from the destination URL: https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/pluggable.php#L1249 In my opinion you have 2 options: 1 – Convert new lines on the message to a diff allowed unique char combination and then replace them back to new lines before outputting … Read more

Extract subdomain and relative address from a url

I encountered a similar requirement, and could not find a ready-made solution for this, so I created a function that is based on the standard PHP function parse_url() and added to this over time to extract everything that I could think of. Below is my code and two examples of the output. This will extract … Read more

CSS not loaded when omitting www. part of URL

This can happen for several reasons – in your case, it looks like you are using a caching plugin that only recognizes www links. I suspect if you turned off caching you would not have that problem, but then you’d lose the benefits of caching. It’s best practice (with or without caching) to add redirects … Read more

Special domain for a page

There is a plugin that does exactly this: https://wordpress.org/plugins/multiple-domain-mapping-on-single-site Anyway, it would be nicer to have things under control with an understandable few lines of script, so I’m still open to answers

Remove slashes (both before and after) in relative post url

It’s because you’re not actually putting the result of ltrim() and rtrim() back into the variable. Those functions return the trimmed value, they don’t modify the passed variable. So you need to do this: $post_url_rel = wp_make_link_relative(get_permalink( $post_id )); $post_url_rel = ltrim($post_url_rel, “https://wordpress.stackexchange.com/”); $post_url_rel = rtrim($post_url_rel, “https://wordpress.stackexchange.com/”); Or better yet, just use trim(), which will … Read more