Adding Snippets

Everything you need to know about creating different sorts of snippets.

How to make a snippet run once per day

By default, snippets run every time your site is visited. If you want a snippet to run only once per day, you can create a cron job. Here's an example: add_action( 'init', function () { $hook =...

Avatar

By Shea Bunge

updated 9 months ago

How to make a snippet run on only one page

You can restrict a snippet to only running on one page of your site by adding this line near the top: if ( ! is_page( 'Page Name' ) ) return; You can replace Page Name with the title, slug, or ID...

Avatar

By Shea Bunge

updated 9 months ago

How to add Google Analytics tracking code

When adding the Global Site Tag (gtag.js) script to your site for Google Analytics tracking, you want to put the tracking code just after the opening <head> tag. You can achieve this using the ...

Avatar

By Shea Bunge

updated 9 months ago

How to add Microsoft Clarity tracking code

If you want to add Microsoft Clarity tracking to your site, you will be asked to add some code to your site's   <head> tag. The easiest way to do this is add a snippet that hooks to the wp_head ...

Avatar

By Shea Bunge

updated 9 months ago

How to add a Facebook Pixel

Adding a Facebook Pixel to your site is easy with when using Code Snippets. When setting up the pixel, select Install code manually , and then create a snippet similar to the one below including...

Avatar

By Shea Bunge

updated 9 months ago

Using AJAX within Snippets to combine PHP and JavaScript

Sometimes when you are working with snippets you'll encounter a scenario where you have a value in JavaScript that you want to pass back to a PHP function. One possible solution to this issue is...

Avatar

By Shea Bunge

updated 12 days ago