WAIT! DON'T MISS OUT OUR LAUNCH OFFER

You could save 50% and lock the price forever by switching to the Premium Annual plan. To proceed with the Pro Monthly plan, click on "Pay with Stripe" below.

Hidden
Freelancers, solopreneurs, small to medium-sized businesses that require a moderate amount of custom features.
Hidden
0,00 €

WAIT! DON'T MISS OUT OUR LAUNCH OFFER

You could save 50% and lock the price forever by switching to the Premium Annual plan. To proceed with the Pro Annual plan, click on "Pay with Stripe" below.

Hidden
Freelancers, solopreneurs, small to medium-sized businesses that require a moderate amount of custom features.
Hidden
0,00 €

50% OFF - LAUNCH OFFER

You're one of the first 200 customers and you get 50% off your annual subscription.

Oops! You need to be logged in to use this form.

50% OFF - LAUNCH OFFER

You could get 50% off your subscription by switching to the annual plan. To proceed with the monthly plan, click on "Pay with Stripe".

Hidden
Businesses and agencies that frequently update multiple WordPress sites and value collaboration.
Hidden
0,00 €

Automatically retrieve fbclid value parameter from URL and store it in a cookie

The code below will hook into the WordPress initialization action, check if the ‘fbclid’ parameter is present in the URL, and if it is, it will create a cookie with its value. This function will be executed on the front-end for every page load.

Total Time Needed :

20

Minutes

Required Tools:

– FTP client

Things Needed?

– Staging website for testing
– Production website for live implementation
– Code snippet to copy/paste

To implement the feature of automatically retrieving the fbclid value from the URL and storing it in a cookie, follow these instructions:

Step 1

Ensure you are working in a child theme to avoid updates to the parent theme overwriting your customizations.

Step 2

Navigate to the child theme directory.

Step 3

Edit the `functions.php` file within your child theme.

Step 4

Copy and paste the complete PHP code snippet provided below at the end of the `functions.php` file.

Step 5

Save the changes to the `functions.php` file.

Step 6

Test the code on a testing or staging environment before deploying it to a live website to ensure it functions correctly.

Code

function wpdevai_set_fbclid_cookie() {
    if (isset($_GET['fbclid'])) {
        $fbclid = sanitize_text_field($_GET['fbclid']);
        // Cookie will expire after 30 days
        $cookie_duration = 30 * DAY_IN_SECONDS;
        setcookie('wpdevai_fbclid', $fbclid, time() + $cookie_duration, COOKIEPATH, COOKIE_DOMAIN);
    }
}
by @Dot_COM