I would always hook it to template_redirect
. Something like this:
add_action( 'template_redirect', 'custom_check_for_redirect' );
function custom_check_for_redirect(){
global $wp_query; # It could work without this too!
if( is_page( 8219 ) )
$days_to_expire = 30;
if (!is_admin() && !isset($_COOKIE['already_visited'])) {
setcookie('already_visited', true, time() + 86400 * $days_to_expire);
wp_redirect(home_url('/welkom'), 302);
exit;
};
};
Related Posts:
- redirect wp-login.php to another page
- Page get parameter doesn’t work with is_single() function
- Template Redirect Function Only Working When Logged In
- Masking logout URL
- Logout/login redirect CSS issue
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- How do I redirect upon login a specific user based on role?
- Ninja form Redirect depending on text field content [closed]
- How do I redirect all 404 error url to Subcategory url
- 404 redirect to previous category
- Login Redirect if Logged in from Specific Page
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- Incorrect redirect after commenting
- How i can put $_GET codes in function.php?
- Why does get_template_directory_uri() not include “www”, only for enqueued stylesheets?
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- Contact Form 7 If Condition
- Solved: redirect to another page using functions.php
- Redirect to other page if login
- Logout Redirect and also WP-login.php Redirect
- How to add array [closed]
- WordPress website keeps loading the maintenance page
- Redirects based on a JSON file
- template_redirect action only firing if logged in
- How to redirect Subscribers on login to specific page, when logging in from a Page
- Redirect to one of two pages after data submitted, depending on the current url
- Wildcard 301 Redirect Using Theme Function
- Competing Login Redirects – Need to be Combined?
- Postback redirect through add_action is not triggered
- Restrict access if logged out except for homepage
- Redirect specific author posts to another url
- Custom download page
- How to create a function to redirect a specified page to another page
- Language switcher for subdomains
- Allow the access over wp-login.php
- How to request login for user but not for bots
- Making an under maintenance page (without using plugins)
- Disable Attachment Page Except for Category
- Redirecting after login except for a specific page
- How to redirect using a custom wordpress api endpoint after form submission?
- Add Javascript code to functions.php childtheme
- Populate acf-field, depending on block name
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- If has action not working as expected
- Update wp_postmeta table based on 2 keys
- Best practice to call a function from a button-link?
- WordPress does not load jQuery
- Disable wordpress update notification
- How Can I Create a Friendly Slug for a Dynamic Page?
- Link product attribute value to a URL – woocommerce
- Google Analytics – add script to functions.php
- custom error message for empty username and password using authenticate filter not working
- Class parameter in get_avatar args doesn’t get added to output
- Redirection from a specific page for users logged in but not with membership
- Deleting guests profile users after 1.5 hours
- Remove check boxes and its label from screen option for custom role
- get variables data from functions.php to template wordpress (without global variables)
- Removing comment lines from all enqueued js files using a filter function
- Modifying a WordPress Plugin
- ACF Flexible in TCPDF
- Function to function shortcode help [closed]
- Last updated posts shortcode in functions.php
- wp enqueue style on about us page
- CF7 select value get to function and reciept value from function
- wp_get_current_user return ID = 0 when used outside of wordpress, such as webhook / fulfillment dialogflow
- Fatal error: Call to undefined function load_theme_textdomain() in /var/www/vhosts/61/151172/webspace/httpdocs/wp-includes/functions.php on line 5
- large image size of 1440×1440 not pulling 2x of 2880×2880 image
- Hide author info in single posts by certain users
- How to reference different css (bootstrap) stylesheets for the header and body of a page?
- Creating a custom functions page wordpress
- Remove text after a dot and a colon in Woocommerce product title
- sort title descending with title with number
- Delete oldest wordpress post (SQL query)
- Add #primary at the end of navlink permalinks on single posts
- search and replace using regex
- post value to function with Ajax and jQuery
- When are the user meta fields created in the database? Admin vs Woo API REST
- Selecting specific query for offset
- Enqueue script if not page template
- External api call and make global variable for any page visitor enters , page-home, page, single etc
- Is_Page doesnt detect my page
- How do you insert code into the sidebar?
- How Do I Unhook This Parent Theme Function?
- price of product can’t return when get data of product in functions.php
- Including Font Awesome in a Custom Theme
- remove_filter function to unhook twentysixteen parent theme function
- WP AJAX Request Not Working
- Test CDN link from function.php or wp_enqueue_script/style?
- Unable to login after registration
- Woocommerce product price change
- Remove the ‘category’ url for one category type
- Can we have conditional CSS styling?
- CSS style and app.js not loading
- Change function without filter hook
- Security when outputing wp_oembed_get code
- Help with with my function for wordpress
- Widget is displayed in two places
- Allow user only create specific tags
- is_email gives me error
- Trying to change widgets h-tags