I found out you could identify ajax requests by the following if-statement
if (defined('DOING_AJAX') && DOING_AJAX)
So problem solved using
add_action('init', 'set_global_pixelcapival');
function set_global_pixelcapival() {
if (defined('DOING_AJAX') && DOING_AJAX) {
} else {
global $pixelcapival;
$pixelcapival = pixelcapival();
global $prev_pixelcapival;
$prev_pixelcapival="";
if(isset($_COOKIE['pixelcapival'])) {
$prev_pixelcapival = $_COOKIE['pixelcapival'];
}
setcookie('pixelcapival', $pixelcapival, time() + 1200, "https://wordpress.stackexchange.com/");
}
}
Related Posts:
- Add class to all meta boxes for a custom post type
- Why does wp_head hook my functions to the beginning of my source code?
- Pass argument to event hook
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Should `wp_login` be used since it’s deprecated?
- Variable not staying set
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Password minimum length in personal subscription [closed]
- How to use a custom hook
- Run a code only on theme activation only during first activation
- Theme activation hook in php class
- WordPress function and string as variable?
- Create a WordPress shortcode using PHP [duplicate]
- How to pass a PHP $_GET variable and fetch/output it?
- Creating WordPress Shortcode with Variable
- Theme not calling Jquery properly
- How to put a form with php code into a variable or shortcode?
- Apply class to every third list item? [duplicate]
- persist a variable set in header.php all the way down to footer.php
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- How to catch wordpress post ID when it’s published
- WordPress redirect redirecting too many times or not at all
- Why does the post_type_link hook everything twice?
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Insert page content into another page with a changed variable
- Pass Variables or Variable Place-Holder from Editor to PHP
- How to access or parse key/values that have “string”
- How to have different site identity logos on each page on Astra Theme [closed]
- How can I hook into the wp_mail function used by BackWPup?
- Can not add admin notices from the edit_user_profile_update hook (notices not being displayed)?
- Get user custom field value on function.php
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- javascript variable to wordpress php variable
- Send notification email to admin for every new post published
- Adding function to child theme’s function.php
- Comapare get_user_meta value
- How to reference PHP in Javascript
- Store and Change Session variable – PHP SESSION VARIABLE
- Overide Variable in Child Theme
- echo var into wp_query
- how can I include some custom variable from functions.php?
- Dynamically adding filters
- Add a custom class to the body tag using custom fields
- Must filter functions receive all arguments passed to them?
- Why doesn’t global $wp_query not get hooked?
- Creating customized php files in theme folder
- Dynamically Generate Functions and Hooks
- How to pass hook variable to function?
- PHP variables in a post?
- WordPress is removing query variables like page, p from the URL of a custom static page
- save_post trigerred twice
- How to sort WooCommerce products page by latest in-stock items first?
- Generate a QR code when creating a new WordPress user
- Replace a single variable with add_filter
- Filter wordpress posts without searching the keywords in the post content
- How to send a php var to jQuery Ajax call with two different file
- Variation prices breakdown only for single product page
- Unable to display multiple parameters from url by javascript through shortcodes
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- How do I add a function to parent theme
- Display custom field value in woocommerce variable product via jQurey
- Prevent header and footer from loading on specific pages with template or plugin
- Add custom field on admin dashboard comments / reviews
- How to check a variable Changes
- Contain multiple page templates in one PHP custom template file in WordPress?
- Show full post instead of excerpt
- global $product is empty string when passed into function
- Use wp_head hook on template page
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Wp_Schedule_Event every few minutes doesn’t work
- Custom global variable not working in function
- Adding custom field to product category and show it to shop/category shop page
- Preserving backslashes in post_content
- WordPress How do I pass a variable from one add_action to another?
- Trouble Accessing Gravity Forms API (GFAPI)
- Best way to use variables in multiple functions?
- Trying to add some custom text into WordPress Post title via function.php
- How to edit post meta data before publishing the post it self wordpress?
- Enqueue assets from multiple directories using add_action/do_action
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Fatal error: Uncaught Error: Class ‘WP_Block_Styles_Registry’
- Call a single function on two different methods with hooks
- Custom meta box is not displaying value showing tag as empty
- using filter and hook inside class
- Get original value in save_post action hooka
- Discount in the specific product title using keyword ( Woocoommerce )
- get Woocommerce product format json for WP_Query
- How do I fix Undefined variable using $_POST in function?
- Register/enqueue scripts only on certain admin pages
- How do I get the value of a current user’s custom field?
- Is there an option to execute javascript file only on plugin activation
- How do I remove an action hook inside a class that is called by another class?
- How to change the value of a variable using input field?
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Help hooking into user_register
- add_filter() inside another add_filter()