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
- No Google Analytics code rendered in the header?
- all plug-ins load scripts on all pages
- Comment IP Plugin – Fixing onfocus=’this.select()’
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- WordPress 5.4 – How to prevent to enter only certain values in custom field
- What form should the $query media query array have for an Elementor page builder function? [closed]
- Private Page View Counter
- WooCommerce: Force coupon for existing/registered customers [closed]
- Plugin Activation Error – The plugin generated 22 characters of unexpected output during activation
- Plugin Admin Menu Boiler Plate
- How can I add IP address to my post?
- REST API can’t get the response manually
- Super slow plugin page (lots of error 500)
- How to make a dynamic css class whose name changes every visit to confuse scraper
- serverSideRender does not render “preview” html inside Gutenberg block
- How use wp media upload liberary in react components?
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- How to notify wordpress instalation about my plugin update?
- Is it possible not to load theme on a specific page in wordpress?
- How to change shortcode’s default theme?
- Integer in Array returns null
- Plugin onclick button activate other plugin
- composer not working on my plugin when i upload it to my website
- wc_get_template new template does not showing up
- How to select a paragraph other than the 1st to be the post’s excerpt?
- Moving Jetpack buttons to appear below the first H2 title on all project/post pages [closed]
- Send email to multiple addresses on Contact Form 7, but exclude personal details on all but one
- How can I support plugins in a custom theme?
- Display site language setting in source code
- Show icons or badges under title on product archives/category pages
- How to get theme’s info from wordpress.org/themes using api.wordpress.org?
- Override/ignore CSS from active theme as not to interfere with my custom CSS
- WordPress Custom Pages that work with Plugins?
- posts from multiple post types in one slider
- How to automatically redirect to custom admin menu after plugin activation?
- How to use the CSS of the WordPress core in the development of my administration page?
- Redeclare function after plugin activation
- add_submenu_page returns null
- What is the WordPress approach to custom data?
- Conditional Shipping Options if Certain Products are in Cart WooCommerce
- Readable titles in mobile
- How to do the simplest possible frontend ajax call from a plugin?
- The XXX plugin has been deactivated due to an error: The plugin does not have a valid header
- How can I add “last updated” in plugin descripton?
- get_edit_post_link() not working on wp-cron
- get_option / wp_localize_script Not Working in OOP Plug In
- New bulk action to resend welcome emails
- Get site url and updates data, then use them
- How to have a gallery in which each image’s caption is a whole “post”?
- I receive taxonomy id