You can’t add headers after content has already been sent to the browser. If you try, you will get those “Warning Cannot modify header information – headers already sent by… ” messages.
Shortcodes execute inside the the_content
filter, and that filter runs well into a page load. That means that content has long since been sent to the browser by the time you try to add headers. To make this work with a shortcode you’d need to do something like what is done here, but honestly, I’d recommend not using a shortcode. That isn’t the right tool for altering early page load content.
I can’t tell exactly what you are doing, but my gut feeling is that a custom meta field would be a better choice.
Related Posts:
- How do I force wp_enqueue_scripts to load at the END of ?
- How do I make my plugin load before the headers are output so I can redirect wordpress?
- Add code into on a per page/post basis
- How to remove/hide action links cluttering under specific plugins’ names
- Change My Basket text in the header of WooCommerce Artificer theme
- How to send “Location” header on plugin form submit event?
- Meteor Slides as header only for homepage and Use featured image of each page as header for respective pages
- Strip HTML comments from plugins in header/footer
- send_headers don’t work on wordpress multisite
- adding meta data using plugin to top of head
- WordPress Redirect Not Working – AJAX Callback Response Not Picked Up
- WordPress repository forbids me call wp-load.php in non-WordPress file
- Show an image in my header.php
- Headers Content-Security-Policy CSP Major Issue
- How to debug error message: Cannot modify header information
- Object method calling for global $wpdb in header.php
- What does making sure “that your theme is WordPress header and footer tag enabled” mean?
- Know which plugin is calling JS in wp_head()?
- My single.php page does not show the related data to the post which is clicked
- Enqueue stylesheet in plugin for wp-login.php
- Get ‘Headers already sent’ error for the plugin I am creating when I try to login
- Custom Login Page — wp_signon Headers Already Sent?
- Adding Plugin Assets to Header
- Content-Security-Policy Headers are there and showing the correct settings, but still getting a refused connection
- echo get_option in header template
- Cannot access WP admin because plugin returns 204
- force jQuery to load in the head
- Edit page header on a custom plugin
- How do i ‘deactivate’ a plugin only on a certain page template?
- how would I include some html in the header section of a wordpress plugin? I get an error
- How do I fill the Home Description?
- Hook for plugin to insert into entry-meta
- sliding/fading header plugin or approach suggestion
- How to make a slider hearder?
- Prevent WordPress from sending set-cookie http header
- How to change the width of certain paragraph or header blocks?
- Modifying server’s response to API endpoint
- How to fix shifting header after installing speed / cache plugins?
- Cannot modify header information – headers already sent during plugin activation
- Debug in WP backend
- How to overlay a webcomic plugin on top of a header image?
- Set Content-Type header in do_parse_request filter
- Primary Menu doesn’t show because of w3 cache
- Insert Plugin on a custom page
- Problems with installing and deleting plugins
- Change text “My Basket” in woocommerce artificer theme
- WordPress repository forbids me call wp-load.php in non-WordPress file
- How to laod wp_enqueue_style to another header i created my self
- Cannot modify header information – headers already sent by
- Footer option is missing in Customiser
- Plugin update error message
- How can I modify what is being output in wp_head, whether by a theme or WordPress in general?
- Where should I use get_option in a plugin
- WordPress Plugin Development from Scratch. How? [closed]
- Disable text tab on WordPress text-editor
- Set a User as Author of all ‘New Posts’ posted
- Passing URL parameters to WordPress pages and pretty url
- How to get the custom page get_permalink?
- Plugin translations problem
- WordPress register_activation_hook table creation not working
- Multisite mu-plugins site-specific directory
- Redirect to a welcome page after updating plugin
- Calendar Solution: Handling upcoming Dates with Posts?
- Disable woocommerce cookies and delete cart data automatically
- Link for ‘Show all Events Categories’ [closed]
- Plugin for single language localisation [closed]
- How to remove/hide Yoast’s “SEO” tab in admin panel?
- Is there an easy way to download all plugins from the repo?
- Is Timthumb still broken? What security measures should be taken?
- Is there any plugin which can paste a common content to my every post?
- Combining several CSS files into one for optimization
- Which filter/action should I use to serve content for “virtual” files
- Is it a standard to have an empty `index.php` in root of Plugin? [duplicate]
- WordPress Fatal Errors [closed]
- What is the best way to hook a rewrite function for certain php code when plugins are updated?
- Undefined index: ratings_score …/wp-postratings.php on line 994
- Does anyone know what’s the plugin for this Comment Section?
- post title not changing at post page
- show wc_add notices on particular page in woo commerce custom plugin development
- Custom Formdata matching with user table
- How to align a text left side while keeping vertically centered? [closed]
- Code Snippets plugin by Shea
- htaccess question and plugins.php
- wordpress plugin page error
- Different Urls for mobile and desktop homepages
- Can’t enable/disable plugins in non bulk mode
- Update page (update-core.php) & Plugins page (plugins.php) revert to homepage
- trying to create simple plugin to filter categories from all authors
- Can’t get custom user meta to show in header
- How can I add the custom taxonomy categories to the posts and pages?
- WordPress Customer Reviews Error: Line 239?
- How to create a page template using custom plugin
- WordPress 3,5 and Jquery version
- wordpress illegal string offset ‘parameter’ error
- How to convert hits from Top 10 plugin to WordPress Popular Posts? [closed]
- WP can’t send newsletters
- Defer parsing of JavaScript [duplicate]
- Update post meta Rest Api
- cURL External API request displays content above other content on page
- Problem moving to category posts page