I’ve used this and it works:
add_action('init', 'optin_cookie', 1);
function optin_cookie(){
$currentURL = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ( $currentURL == 'https://25dni.si/delovanje-uma/' ) :
setcookie( 'opt_in', has_opt_in, time()+31556926, "https://wordpress.stackexchange.com/");
elseif ( $currentURL != 'https://25dni.si/' ) :
if ( ! isset( $_COOKIE['opt_in'] ) ) :
endif;
endif;
}
I’m sure there is a much more elegant way to do it, but this got it working for me …
Related Posts:
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- How to combine wordpress_logged_in cookies in one cookie?
- how can i use $_COOKIE[] + PostID to execute the below code?
- How to make a cookie be on the whole site instead of being on a specific page/
- WordPress load javascript file if something… (after the page is loaded)
- Allow user to select location and then set cookie for location in WordPress
- Use WP_Query Data In Cookie
- Keep users logged in Without Remember Me
- Cleaning up WordPress to improve performance?
- List of all theme customizer control types?
- Modify previous and next text from pagination links
- How can I modify the permalink via a filter?
- Shortcode putting html such as
- Calling a method from functions.php on a click of a button
- How to redirect users to custom lostpassword page?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to change featured content to a different tag in WordPress Twenty Fourteen?
- How do I create comment-reply-button using element not
- WordPress menu deletes when trying to add a hook
- Overriding a theme redux file in child theme
- Validate a users email address when using gmail to register
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- How to check If Oembed is empty or not
- Making Quote Plugin more efficient
- allow subscribers to see private posts without plug in
- Displaying the Month and Year that a page was Created?
- Only Show Link If div Exists
- How to access global variable $menu inside a class function
- Change the WP Video Shortcode Output
- How to pick the default selected value in wordpress dropdown?
- Using WP-API and SSE not authenticating user ID
- Validate functions before inserting then into functions.php
- How to retrieve current wordpress profile page URL?
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- Modify function to print tags/categories/exclude tags/categories/ number of posts
- Search not showing all results
- How to Reference/Echo Variable from Another PHP Function
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- How can I make an object available through the entire site?
- WordPress admin-ajax.php
- What exactly do this function declared into functions.php file of a WP theme?
- How do I modify the custom footer text and get theme version number to show in wordpress admin?
- How to use html inside a functions.php code?
- Nested “do” and “add” Actions is possible?
- Display Data in Table from External Database in WP using Shortcodes
- How to check if a Customizer setting is set?
- linking stylesheets and scripts with functions.php
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Remove item in Checkout
- How can I hook into the wp_mail function used by BackWPup?
- How to get current post category details inside “loop”?
- Only load certain artists on this page
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Get the alt text of the image in a array
- Convert all uploaded PNG files to PNG-8 format
- Make table disappear when fields are left blank?
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Woocommerce order status payment
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Unzip file in functions.php, and add it to cron
- Add Block Before Entry Title Using PHP
- Display logged in user name and lastname on page
- How to Add a cutsom slug to my custom author role
- Dynamically populate parameter in Gravity Forms using PHP
- Store ajax data in PHP variable
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- How to output the taxonomies that are assigned to each custom post?
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- How can i create a function tag in my plugin
- How to escape echo for input tag?
- Including user data in “new user notification email”
- Display current user metadata on WordPress page
- Reload page with a different shortcode when a user selects from a dropdown
- Refresh page after login with litespeed cache
- Return newly created category by code
- Woocommerce Add custom “Add to cart button” in single page with tags
- Hook into all password resets in WordPress and get password before hashing?
- remove_action() not working in page template – Genesis
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- Dropdown menu on custom menu
- What is wrong in this code?
- How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
- WordPress get_post_meta issue
- Woocommerce Price Text
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- Show custom default avatar instead of gravatar
- WordPress 2014 Theme – Featured Content with multiple tags?
- ajax form function error
- Display custom meta box in my template file
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How to display the date under the post title?
- Simple Probléme in wordpress
- Why can’t I enter the wordpress admin interface?
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- Contact form with dynamic dropdown and filter
- Critical Error customiser
- Understanding responsive imagery
- How to get meta box labels?
- How do I stylize selected comments?
- Tags being Inserted in html from plugin PHP not passing through the_content