This line (at least) is being output before the cookie can be set:
echo '<h2>'.$hash.'</h2>';
Sending output to the screen (even empty lines) will prevent cookies being set.
From the PHP docs:
Like other headers, cookies must be sent before any output from your
script (this is a protocol restriction). This requires that you place
calls to this function prior to any output, including<html>
and
<head>
tags as well as any whitespace.
Related Posts:
- What is the criteria for pluggable functions?
- How to overwrite / extent wordpress function is_email
- Why There Is No “get content by ID” Function
- How to override parent functions in child themes?
- Adding a second email address to a completed order in WooCommerce [closed]
- How to override a function when isn’t at functions.php
- How do I use the WP image functions in a page template?
- Removing custom background and header feature in child theme
- syntax for remove_filter in parent theme with class
- Is it possible to override this function/class in a child theme?
- How to prevent deleting of comments when deleting a post
- Convert hyphen to underscore in permalinks
- Conditional tag is_page with a custom post type
- How to override filter in child theme?
- Customized wp_new_user_notification
- change default option in wp_dropdown_categories
- WP_Remote_Get Not working
- Use register_setting() in a loop
- How to edit the Tags within the image file URLs?
- How to target post and pages and not all post types in admin?
- the_posts_pagination() function returns missing page numbering on some blog pages
- Filter an WordPress Function in (general-template.php)
- Auto log in hook is requiring a page refresh
- Allowed memory size of 33554432 bytes exhausted (tried to allocate 9967617 bytes) in …\wp-includes\functions.php
- overwrite code snippet from parent to child theme
- Where to store credentials used in a function? [duplicate]
- Solution dealing with Child Theme / Parent theme functions
- How to override this theme function in child theme
- WordPress login set cookie that survive browser exit (wp_signon function)
- I have an fatal error on my funcyions.php
- “Conditional query tags do not work before the query is run. Before > then, they always return false. “
- WordPress reading old version of functions.php, breaks site
- Providing fallback function and allow override by plugin
- Integrate WP Tiles into existing loop (index.php) and theme
- disable WP_error: authentication_failed
- save_post hook – headers already sent?
- Override default password nag in WordPress
- is_preview() always return false
- Customize Notification Email Sent to New User When Manually Created by Site Administrator
- How can I edit the wp_parse_auth_cookie function from the pluggable file in my functions?
- How to cache results of of get_available_post_statuses() function as it is causing a slow query on a website with over 1 million posts?
- WordPress internal functions : why not use them?
- Author info does not show up when author has no posts
- How to create a function to redirect a specified page to another page
- how to display featured image for single post for a specific category
- us states dropdown function and echo in theme template files
- Adding a meta box fields to child theme options page
- Nothing happends on post_update
- Multisite Admin Roles
- WordPress not showing pagination links
- How to wp_enqueue_script with html?
- Automatically add tag if a checkbox is checked
- Database SQL Error, Should Work
- Database Query not working
- Adding a jQuery rotator function
- Can I use a function to return HTML and the result of another function?
- How to pass a variable from a template page to the child theme functions.php
- Instead of using $post, how do i get the thumbnail image of the $post
- Login functions
- Home/Static Page View for Visitors pages after that should be restricted
- functions.php filters not applied in AJAX call
- wordpress not calling peliegro functions.php?
- Dynamically generated Navigation Diagram using Custom Fields
- Child Theme functions.php has no effect
- Setting a cookie in functions.php and it gets deleted when working on an other function
- Hide certain post types from editors
- Problem with add_rewrite_tag
- Add functionality to post editor
- Update add_image_size
- Language switcher for subdomains
- custom post with loading script per single post
- getExcerpt: Make ellipsis appear only if character limit is reached
- Define an extra field for all pages (with no plugin?)
- Function to draw random image from specified category destroys site logic – why?
- Issues with add_query_arg() not passing a variable
- update_post_meta not working in function
- WordPress permanently logging users out
- What add_action reference should I be using or should I use do_action?
- What is wrong with functions.php? Fills error log with same error
- Function returning queried meta value based on current post ID
- List all post title in category using functions.php
- wp_enqueue_script only works outside of action
- How can I include user meta information in the resulting array of a WP_User_Query?
- How to add next height number in Order Attributes inside the Add new page. [duplicate]
- Adding custom field in menu options [duplicate]
- Quicktags external functions file
- Pagination in Search result
- Custom field not updating via functions upon publishing
- Pass max posts to Javascript
- Updating site content after an AJAX call without a page reload
- Function the_content
- Problem in outputting shortcode
- Edit TinyMCE Button Functionality
- need help with ‘… read more’ excerpt in functions.php
- Problem in shortcode outputting content
- Load a Child Theme’s style.css just before the closing tag
- Load CSS conditional on custom field is present
- Can’t wrap my head around this function – any help would be appreciated
- Modify sub_menu function to show pages below a specifically set page
- Figure inlined width trigger distorted layout