Found the answer (via)
Instead of using the function I added an action to “wp_loaded”, that makes sure that it gets loaded before any headers are sended.
<?php
add_action ('wp_loaded', 'my_custom_redirect');
function my_custom_redirect() {
if ( isset( $_POST['subscribe'] ) ) {
$redirect="http://example.com/redirect-example-url.html";
wp_redirect($redirect);
exit;
}
}
?>
Related Posts:
- Auto get_header and get_footer on every template?
- redirect does not work in ajax function
- How can I get wp_head() as a string instead of echoing it?
- Template Hierarchy for get_header()
- How to remove header images from all pages except the home page? skeleton theme
- Add social icons in a theme through custom admin menu
- Fatal error: Call to undefined function get_header()
- How can a Theme Contain no Header File or Footer File?
- How do the default themes reference style.css?
- How to remove the header from all pages except home?
- Create wordpress header with custom logo in between the menu splitting the menu into two equal parts [closed]
- How to remove header image in Twenty Eleven theme?
- How to create a fixed header and scrolling content area
- Dynamic menu links after header title
- Second menu has the first menu ID
- Changing footer depending on URL (poli language site)
- header, stylesheet not being read
- Why is the `if else` not working?
- How to add cropped custom header image?
- remove_action(‘genesis_header’,’genesis_do_header’) hook not working
- Change header image on a particular page
- Check if redirected from a specific page template
- Dynamic meta description
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- How to create full header but keep content narrow
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- Is there a has_more_tag() method or equivalent?
- Why is wp_redirect() preferable to a standard PHP header redirect?
- Hide a div that is part of all pages on one specific page
- How to force Media manager to overwrite files of same name?
- How wp_cache is supposed to work, and does it help with performance?
- is_home() returns false on the home page! When is the home page NOT the home page?
- Why does my short code get executed before other content?
- Enabling Widgets By Default in Custom Theme Development
- How to fix the error “file_get_contents was found in the file functions.php”?
- Identifying the priority of style.css so I can make a small CSS file load last
- WordPress Customize — Move “menus” options / field to another section
- How to use the responsive images feature from WP 4.4 in your themes
- What are WooCommerce starter themes? [closed]
- Modifying JS files in Child-theme
- How to support Lazy Loading Assets in a WordPress Theme?
- Convert PHP readfile to WP_Filesystem
- Wysiwyg editor for P2 theme
- Sub folder CSS that’s read by Admin panel
- Toggle Sidebar Display
- Dequeue a style file which is making website load slow!
- How to customize save function event?
- WordPress page templates in a directory
- Do I need normalize.css when developing my own WordPress-theme?
- WordPress Redirect Not Working – AJAX Callback Response Not Picked Up
- How to move the the_excerpt’s read more link to another div
- Limit Loop to 5 Posts?
- Table of Contents Before first heading
- Theme-wide custom post template
- comment form args are not translatable (customized comment form)
- Zoom on custom theme without child
- Changing a slider to a grid [closed]
- What do with the index.php … [duplicate]
- How to add Space between sidebar and footer widget in WordPress theme [closed]
- Custom Navigation build using wp_nav_menu and walker
- Question regarding WP multisite feature
- Call to undefined function add_menu_page() on theme activation
- “Theme without sidebar.php is deprecated”
- Is it acceptable for a WordPress theme to not accept widgets?
- Should all references to a text domain be to my current theme?
- my excerpts lack the ‘more’ link
- Simple child theme modification but links are broken
- Is functions.php in themes applied to all templates?
- Doing context-aware previews in the WordPress Customizer
- how do i develop a global nav and local nav to be wordpress dynamic?
- Why Tags don’t appear in my page?
- First post full width without Sidebar
- How to make a theme unable to be used on a multisite network?
- best practices for updating wordpress theme
- Multi Site Setup, Child Themes, Getting Style Sheet Directory
- if (has_custom_menu())?
- Exclude parent categories from the_category() within the loop
- How do I pass the category object to a function when is_archive() is true?
- Making a horizontal flyout menu from WordPress category listing
- How to use Canonical URL meta tag to avoid duplicate content issues with WP home pages
- getBoundingClientRect() showing different values on load vs scroll
- Ensure SQL changes carry over
- How can I set multi archive page template on same time for only one custom post type?
- Exclude categories from wp query not working
- Copying a modified theme from one wordpress site to another wordpress site [closed]
- Show Yoast SEO meta tags in Custom WordPress Templates (Theme)
- using themename_the_custom_logo() in template-tags?
- WordPress doesn’t load css, image and js files after moving local installation folder
- Customizer Image-Picker Preview Not Working
- How to get url image page the right way?
- Mobile view logo background colour in wordpress
- Strip HTML tags on custom code from the_content
- page.php is not called when I load a Page
- Main Menu Theme Different Output Print
- WordPress loop not working on blog.php page
- Option to show/hide widget depending on is_home?
- IS there any reason not to include javascript in my own post’s embeds?
- How to create more templates to the same theme?
- How do I middle-align my header menu items in WordPress [closed]
- How to add Dummy content when active wordpress theme without xml import?