Skip to content

Third Party Scripts

Many WordPress sites require external tracking, analytics, or functionality scripts. This page explains how to add third-party scripts to LumberMill.

LumberMill includes a built-in ThirdPartyScriptsHook that reads script snippets from ACF option page fields and outputs them at the correct positions. This lets content editors manage scripts without touching code.

The three fields on the Theme Settings options page are:

Field keyOutput location
theme_settings_third_party_scripts_head<head> via wp_head
theme_settings_third_party_scripts_body_openAfter <body> via wp_body_open
theme_settings_third_party_scripts_body_closeBefore </body> via wp_footer

Paste the full script tag (e.g. Google Tag Manager, Meta Pixel) into the relevant field and it will be output automatically.

For scripts that need to be added in code, create a method in a hook class and attach it to the appropriate WordPress action.

public function register(): void
{
add_action('wp_head', [$this, 'addGtm']);
}
public function addGtm(): void
{
echo '<script>/* GTM snippet */</script>';
}

Available actions:

  • wp_head — insert in <head>
  • wp_body_open — insert after <body> tag
  • wp_footer — insert before closing </body>
public function addInlineScript(): void
{
$value = get_some_option();
printf('<script>var myVar = "%s";</script>', esc_js($value));
}

Always escape dynamic values with esc_js() for JavaScript strings.

External scripts can be registered via the config/assets.php file.