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 = 'run_snippet_daily'; $args = array(); if ( ! wp_n...

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 of the page you want to run the snippet on, or ev...

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 tag. You can achieve this using the wp_head action hook. Here's an example: add_action...

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   tag. The easiest way to do this is add a snippet that hooks to the wp_head action. Here's an example: add_action( 'wp_head', ...

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 your pixel base code: add_action( 'wp_head', functi...

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 to make use of AJAX. This article is intended to ...

Unlock Design Power with CSS Snippets in Code Snippets Pro

Learn how CSS snippets in Code Snippets Pro give you full control over the design of your WordPress site. With simple, powerful CSS code, you can easily tweak styles and create a unique look. Includes basic examples and a link to further learning.

Why You Need JavaScript Snippets with Code Snippets Pro

Discover how JavaScript snippets can transform your WordPress site by adding dynamic features and interactivity. This article explains the benefits of JS snippets, with basic code examples and a link to a helpful JavaScript guide.