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
- get php variable from functions php and echo it in theme template files [closed]
- Remove Container Element From wp_nav_menu() Markup
- WordPress function like is_category for subcategory? is_subcategory?
- Using a private method as an action callback from within a class
- Auto close (hide) custom metabox / set default state
- Does WordPress Development Mode Exist (with not minified JS)?
- WP_Query in functions.php
- wp_delete_user with username
- what is the meaning of settings_fields()
- Organize functions.php
- How to activate “Description” metabox for menu item programmatically?
- Change labels on ‘Nickname’ and ‘Biographical Info’ in user-edit.php
- Edit the_content function
- write in functions.php
- How to set child post categories to parent post categories when updating parent post?
- get excerpt without images
- WooCommerce add_action hook results in 500 error
- Advice: Template structure – php blocks in sidebar or someting else?
- Help to resolve Syntax error, unexpected ‘endwhile’ (T_ENDWHILE) [closed]
- wp_get_post_terms() returns WP_Error in functions.php but in template it works
- Removing the first image in content
- Make menu structure match page heirarchy on page parent change
- Global functions on WPMU
- Change template dynamically
- is_account_page() change to page slug
- Modify a function without editing template
- Override widget in function WordPress
- How to change or add user role after getting post request data about pay? [closed]
- How to properly remove style for non logged in and front page only
- WordPress converts media extention URL automatically to video player
- How do you Permanently Delete Sidebars
- Add a unique class to HTML tag/element
- Which function required?
- AJAX error handling for submit function in functions file
- get_pages() Returns Only One Item
- Custom Query Not Paginating
- Getting the teaser text without overriding global variables
- Solution dealing with Child Theme / Parent theme functions
- Function to pull data from user meta not working
- referencing the current user in a page i created in wordpress
- Counting posts and trigger it [closed]
- Replace theme function
- Is it possible to use ‘wp_insert_post’ function within a for loop?
- save_post function keeps triggering: Warning: array_map(): Argument #2 should be an array… when restoring from trash
- More than one search results page template for two searches on site
- How do i create a search option for pdf’s only
- Redirect after login to current URL
- Restrict certain roles registrations by domain
- Replacing term/taxonomy archive pages with search queries
- Return ACF Field value function
- Best way to add image to recent posts widget?
- Issues with add_query_arg() not passing a variable
- Force changing the Site Title and add link
- create submenu page – error function not found or invalid function name
- Undefined offset: 2
- Sorting date results from a query
- Using is_plugin_active within functions.php
- Button generate a random URL [closed]
- How to Delete Posts by title?
- How do I add functionality to images?
- Display function from functions.php in tag.php
- function to show youtube videos within excerpt – if condition and apply_filters