If you want to add headers this can only be done before you are returning data. Headers are send at the start of a response from the browser.
What probably goes wrong is that you have an empty line on the top of your file. Or you do somewhere an echo (or something a like). Then PHP starts outputting data (thus returning stuff to the browser). Then you’ve missed your change of adding headers.
Please check if you don’t have an empty line in your file like this:
.empty first line or any char here.
<?php
echo 'hi'; // Echo here BEFORE your setting any headers
?>
.or an empty line/char here?
Related Posts:
- Gutenberg disallow certain custom blocks but keep all core blocks?
- Why does WordPress still not support SFTP?
- Hide wordpress plugins from list
- WordPress plugin from own server
- How to avoid plugin name conflicts from the upgrade notifier?
- Adding unit ammount after WooCommerce price. Example $ 24 /m2 and $24 / m
- How do I only load a plugin js on it’s settings pages?
- Can a plugin cause permanent damage?
- Moving image attachment from post to another?
- Use functionality of 2 wordpress plugins
- Under which circumstances is the .maintenance file not deleted?
- Suggestions for i18n plugin [closed]
- Autoload via composer in plugin interference
- WP-Members redirect if member ALREADY logged in
- Can WordPress plugins “Talk to each other”?
- WordPress plugin form not saving data
- wp_mail attachment not working
- Undefined property: WP_Post_Type::$ID
- Plugin exceeds memory limit
- Plugin Paths Issue
- How to remove html code in excel downloads using phpspreadsheet with wordpress plugins shortcode
- How do you export/download the file of an already-installed plugin?
- Woocommerce plugin for minimum order and add-to-card-step
- How to override a plugin function wrapped in a class?
- Load custom PHP on a custom URL via a plugin
- submit posts by unregistered users in wordpress
- WordPress Settings Lost After Site Migration
- How to put JQuery/Ajax inside shortcode?
- Programmatically Process Order through WooCommerce/Stripe Payment Gateway [closed]
- How do I get fresh post data in post_publish hook?
- WordPress Widget Not Saving Data
- How do I use wp_editor() in widget form?
- How to create an option page for this simple plugin
- How to reorder and display a feed to be chronological?
- Errors when trying to use a plugin to write to the database
- _prime_post_caches in wordpress
- Can some vulnerabilities in plugins be exploited even when the plugin is inactive?
- Plugin settings won’t save changes
- WPTouch – how to remove shortcodes or make shortcodes function
- Adding class to last list item? Not WP generated
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- Custom shortcode for displaying user based on a role parameter
- How to execute plugin and theme updates from a web hook / endpoint?
- WordPress Plugin Insert Html Code with Shortcode
- How to remove index meta tag
- don’t call ajax if not plugin page
- WordPress gtag.js with User ID tracking
- trigger email when post is published by someone a user follows
- WP Rest API and json_decode()
- Disable submit button order
- Install old version of plugin from admin panel?
- insert an html tag using php plugin
- Can we give Pending as a Role to wp_insert_user?
- Rename Smart YouTube’s httpv back to http for all posts
- Custom page from wp admin area
- Create category for each user
- Avada Live is broken on WP
- How page with random php file with query params generated
- location lock wordpress website
- New Plugin Info request
- Membership and search criteria
- WooCommerce Product Table – filter query on attributes
- Why does plugin_url append absolute file path?
- Disable WC Bookings automatic order completion [closed]
- WordPress Sumo Plugin not showing all images on clicking pinterest icon
- Insert Google Maps HTML in WordPress
- WP nonce verification
- Call to undefined function add_action() in plugin
- How to make my wordpress site Multi-region
- Created wordpress using quick install on Hostgator but unable to access the URLS
- How to add separator between default and custom panels in WordPress customizer?
- Having trouble going from Jfiddle to implementing in WordPress :(
- Buddypress Member list not showing admin and mods
- SVN problem – commit taking forever to fix incomplete prior commit
- Editing a built plugin: How to activate it only on a single post page
- pluggable function in theme, to be overridden by plugin
- Restrict my pages from public
- Migrating site from stage to production server without particular dev. plugins?
- Using “excerpt_more” filter for a specific post type
- w3 total cache and post__not_in
- Plugin programming: Uploading a file to a specific folder
- Conditional statements using category and Tags
- Shrinktheweb plugin problem
- Backup Buddy Questions
- How do i use postMash to order posts in a custom loop?
- How to link that “logged in” in “you must be logged in to post a comment” with custom login page on WordPress?
- Get value of a key from a Plugin Serialized array
- Get post id in Post Page within Wp-admin
- Simple WordPress function / plugin to redirect a site
- How to declare this function correctly?
- How to show in front End images using Visual Composer attach_images?
- Plugin version number after code rewrite [closed]
- Getting 400 Error in wordpress website
- How can i store cache of wordpress a database request without plugins?
- disabled plugin and now wordpress won’t load
- How to provide page_template path in custom plugin using WordPress
- WordPress User Registration/ Sign Up -> Able to take Paid Certification Courses & keep track of Completed Certificates
- Prevent primary navigational menu from expanding during page load (WordPress / Astra Theme)
- WordPress theme development – the template dropdown in Pages and disappeared
- Add custom button to the changeset status in the Customizer