Your method is called too late. I don’t know how you call this method but you need to run it before output is sent to the browser– usually that means before get_header()
. There are a number of hooks that can be used. For example (from https://wordpress.stackexchange.com/a/131210/21376):
add_action(
'template_redirect',
function() {
if (is_single()) {
wp_safe_redirect(home_url());
exit;
}
}
);
Without more context, it is impossible to say exactly what the right hook is.
Related Posts:
- wp_redirect() is not working
- wp_redirect problem using code snippets
- How does one suppress a 404 status code in a WordPress page?
- disable wordpress canonical tag meta
- Why is wp_redirect() preferable to a standard PHP header redirect?
- Disable h1 and h2 from rich text editor combobox
- Recommended location to set response headers?
- Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?
- Custom endpoint and X-WP-TotalPages (headers)
- Additional Option on Custom Header admin
- How can I use CURLOPT_USERPWD in wp_remote_post?
- If Modified Since HTTP Header
- Error messages when adding code to function.php or trying to delete inactive plugin files
- Indenting (tabbing) WP_head
- Change the headers content type with wp_remote_post
- Perform a redirect after user action
- Why I can’t add a script-code into theme-settings without 403-forbidden?
- Cannot modify header information – headers already sent by pluggable.php
- Is it wrong to put header tags inside WordPress help tabs? [closed]
- Authenticate a user for current request
- WordPress Redirect Not Working – AJAX Callback Response Not Picked Up
- Facebook embeds loading the wrong language
- Banner in WordPress
- Remove all WordPress HTTP headers (not in-source embeds)
- WordPress 502 | Header Upstream send too big
- Creating dynamic header and footer files
- Strange 403 header response
- ‘Headers already sent’ Error When Redirecting from add_submenu_page() Callback
- “Cannot modify header information” means I can’t use wp_redirect
- My header not showing up [closed]
- How to Access Script Tags in Header
- Where are my js and css links in header?
- Why does WordPress allow inserting tags into posts?
- Problems accessing stylesheets/scripts loaded in WP header
- Rotate images in header based on date
- How to add some lines to the wp-login.php header via functions.php?
- allowed_http_origins() only works in theme functions.php
- Is this a correct usage of ob_start() in my WordPress project?
- Insert stylesheet into WordPress header?
- How to register and set http/2 server prefetch for a specific asset?
- Header with content
- WordPress Template not getting my Sub-Header File
- How to add social follow button to header? [closed]
- Include two headers
- What is this HTTP_REFERRER “WordPress/4.1.2”
- Empty lines in header, how to remove them
- Benefits to using CSS for header image instead of html img tag [closed]
- Export Header and Footer
- Custom headers in WordPress, are there also custom footers?
- Point get_header() to different plugin
- Front end posting, not working wp_redirect with ‘cannot modify header information’ error
- Headers already sent on a frontend post form using wp_redirect before get_header
- Inserting iframe right after on header.php
- Code needs wrapper/container to put footer back in, but where?
- How can I remove or change the tooltip of an icon
- Design Header meta on single posts wordpress
- Including PHP files in header.php
- Remove server response header
- Using a nonce Content Security Policy header for style-src for inline style elements returns errors
- How can I use an iframe element as my header media?
- How to make my banner (logo image) position on the center
- Easiest way to use relative URLs in my WordPress header
- Should I use do_action in the header file?
- set cookies on certain page only
- Video Header in 2016 theme
- Warning: Cannot modify header information – headers already sent by
- Stop plugin from adding cache headers
- my dashboard does not have the option to fix the header or change the theme. how can i get that to show?
- How to prevent a style sheet to affect a header.php or footer.php?
- How do I change top header background color
- Why is http header providing 404 while site is online?
- only header is showing up in posts
- Redirect users in first login to a dynamic link
- force download a file in template_redirect hook
- video header in desktop view, image header in mobile view
- Force download of MP3 file in Safari
- How do you find the logo code on theme file or where can I find the header theme file?
- If is single in header.php [duplicate]
- show wordpress data without headers
- Override theme metadata in header
- Header Image instead of dynamic text
- Code to Show for One post only in head
- Download custom file in wordpress backend [duplicate]
- Removing old code from header
- Random header image but also specific header for certain pages
- How to remove uncategorised posts from WordPress
- Dynamically changing header text depending on URL in WordPress html page
- After being hacked Fatal error: Call to undefined function get_header() in 404.php on line 1
- change headline of page
- making posts linked outside of WordPress still use the same header and footer
- gravity form login widget redirect
- How change the header color?
- How to remove lines over text using Phlox theme with Elementor Pro?
- Loading second header.php for other homepage showing double header.
- My CSS, footer and header don’t show up!
- End of script output before headers – multiple apache error_log errors
- WordPress custom header parameter combine with cache
- wp_redirect() doesn’t work
- How do you modify HTTP response headers on feed/?
- How to add meta description correct way