How to add additional http header to a wp_error rest response

WP_REST_Response extends WP_HTTP_Response class, which has a header() method for setting headers. Using the rest_request_after_callbacks filter should allow setting the header, but will need to duplicate the functionality of WP_REST_Server->error_to_response(), which at time of writing calls rest_convert_error_to_response(), so that’s easy enough. Here’s what I think this will end up looking like (untested). add_filter( ‘rest_request_before_callbacks’, static … Read more

Content Security Policy blocking images from installed plugins’ popup info window, as they are from external domains – global fix?

The answer, as mentioned in a comment by @JacobPeattie, was to add the domains to my .htaccess file where I am setting the CSP Headers, (turns out most plugins’ “View Details” link loads images from ps.w.org, which I just learned). A few other plugins loaded images from other domains, so I also added each of … Read more

Why is there a bunch of WordPress HTML code in my browser CSV download?

This code cannot run in a shortcode: if ( $_SERVER[‘REQUEST_METHOD’] == ‘GET’ && isset($_GET[‘CSV’]) ) { require_once __DIR__ . ‘/../assets/helpers.php’; // contains csv_download() function csv_download(); } The problem is that by the time a shortcode executes it’s too late to send HTTP headers, and WordPress has already sent the theme header and HTML body tags. … Read more

No Google Analytics code rendered in the header?

Thanks @Danijel for providing the link to their github. I’ve played around with the theme and I found that you should make changes here https://github.com/presscustomizr/customizr/blob/dev/templates/head-no-model.php It seems that the code from here https://github.com/presscustomizr/customizr/blob/dev/header.php#L10 is executed and doesn’t reach to your added code. I was able to see the GA script after adding the code in … Read more

How to add meta description correct way

To add a meta description to your WordPress website, follow these steps: Install and activate an SEO plugin such as Yoast SEO, All in One SEO Pack, or Rank Math. Once the plugin is installed, go to your WordPress dashboard and navigate to the page or post that you want to add a meta description … Read more

wp_redirect problem using code snippets

You can’t use wp_redirect or make HTTP redirects from inside a shortcode, redirects must happen before HTTP headers are sent out, before any HTML is sent to the browser, so shortcodes will always be too late. So I looked around and I believe the problem is that some content is sent to the browser before … Read more

How do you modify HTTP response headers on feed/?

If you just want to change the Content-Type header, then the feed_content_type filter can indeed be used for that purpose. (If your code isn’t changing the header, then another code might have overridden that header, so you can try using a lower priority for your filter callback) But there’s another filter hook you can use, … Read more