init
is too early (it happens before the main query), use the action template_redirect
instead.
And for the ID use get_the_ID()
.
Example:
if ( is_singular() )
setcookie( get_the_ID(), 'visited',time() + ( DAY_IN_SECONDS * 31 ) );
Related Posts:
- Is it possible to use a single custom post as the site front page
- Listing a post’s categories and subcategories
- Single post comment template not working
- How do I show google ads between post content?
- Add inline style to get_the_category_list
- Help with figuring out the future post workaround
- Disable single view for specific post category
- Only nextpagelink on wp_link_pages
- Display a post map on a blank/new page
- How To Pass Current Post Type ID from Single Template To Custom Page Template
- Is it possible to create rel=”noindex, nofollow” for a single post if contain bad keywords?
- Custom seperate Single.php
- Custom post type not respecting template hierarchy
- diffrent style for post single page
- WordPress object for comments frame [closed]
- I’m having a problem viewing the Youtube video
- Use different «Single.php» for custom categories
- force https except one page/post
- Single custom post type template not working (single-custom_post_template.php) not working
- Single.php category entries not showing right colours
- Link from archive-page.php to single-page.php
- How to check if a post is in categories x,y,z inludint their subcategories
- Changing the display of the themename_posted_on() function
- How to Highlight current category on category and single page template?
- Exclude single page from function
- WordPress, alternative single post template
- get full real path of thumbnail post img wordpress
- how to loop through this in blog single?
- Modify post template on Divi Theme
- I want to signin from first wordpress site to other wordpress website without registration..without using network mode
- Try to showing product file size on product single page
- Improve related posts
- Get active term on single (CPT) page
- Having single posts appear under the blog homepage and highlight menu items properly?
- Single.php loading fully on localhost but not on server
- explain why is_single doesn’t work
- How to include landing page with form submission?
- Why does it say: ‘Cookies are blocked or not supported’?
- How do I get the category URL from get_the_category?
- How do I create a link that will always show the latest post?
- Posts in multiple Categories different single.php
- Setcookie works on admin but not front end
- Using previous_post_link and next_post_link to wrap around post sequence
- How do I create new content pages for my Custom Post Type?
- Manipulating cookie on specific taxonomy archive page
- Problem with single-page for my custom post
- What is cookie “U” from domain “.adsymptotic.com” found on the WordPress page? [closed]
- Custom template for post type not working
- Which action fire in front-end single post only
- How to fix samesite attribute in wordpress for chrome errors?
- jQuery cookie not working properly in wordpress
- 404 Page Not Found for Only One Post
- Pagination on single post page?
- Custom post template for particular posts
- Will setcookie work if there is a cache plugin installed?
- Remove post templates from the selection box menu when creating a single post
- How I can share cookies from my dimain to subdomain?
- global variables in templates
- On single.php, fetch 2 posts created after and 2 posts created before in relation to the actual post (using menu_order)
- Get term name without a foreach loop
- How to set a cookie for logged in users to md5($user->ID . “my_secret”)?
- Force redirect single.php to index
- Cookie set without HttpOnly flag
- My php code is not being executed
- Getting a person’s username from a wordpress cookie
- Help with a custom rewrite
- $_SESSION variable not saving on page refresh or new page
- Can I “protect” a page with a form asking for an email address?
- How to present a div only when the index.php is accessed for/by the single post pages
- Page specific cookie
- get_terms (or tax_query) for term of current post?
- How to set cookies
- How to read third party cookie to access password protected pages
- How can I set up a splash page that is redirected to only one time for the visitor? [closed]
- Custom Post Type Specific Post Template
- infinite loop on page with comments after changing comments.php and header.php
- What are the issues using the Test Cookie Fix?
- WordPress – When visiting a `single post/ single.php` my category menu item link becomes active
- Favicon not loading until cookies are accepted?
- How to verify which WordPress user requested the API in ASP .NET Core?
- Loop all post on single.php
- Change auth_cookie_expiration for specific roles and specific login times
- How can I get an updated cookie in header.php?
- Ajax login fails: script sets cookies, but is_user_logged_in() returns false
- Different template parts when on different pages
- Extend Cookie with auth_cookie_expiration not working
- custom post type single page
- custom post type single post preview for pending status
- Why does WordPress use cookies for /wp-admin and /wp-content/plugins for non-admin users [duplicate]
- Implementation to count page visits of unique visitors based on a cookie
- If is single in header.php [duplicate]
- DIVs not showing correctly on CPT?
- Custom post type single display is ommited
- Query child posts on parents single.php?
- set cookies for my whole site is not working
- No matching template found when using single.php
- Modify the third (context) parameter in a filter?
- Keep users logged in Without Remember Me
- How to set and retrieve cookies while in the loop
- How to remove without touching the pluggable.php the wordpress_logged_in cookie to show the username on login?