add that code to a js in your theme folder (or child theme if you’re using it). for this example I named the script “analytics.js” and put it in a directory called “js” in my child theme folder.
Now register and enqueue the file by placing this code in your functions.php
function wpse_load_script()
{
// Register the script like this:
wp_register_script( 'analytics-script', get_stylesheet_directory_uri() . '/js/analytics.js', array( 'jquery' ) );
// You can then enqueue the script:
wp_enqueue_script( 'analytics-script' );
}
add_action( 'wp_enqueue_scripts', 'wpse_load_script' );
Related Posts:
- Adding fields to the “Add New User” screen in the dashboard
- Displaying the number of updates available in the Admin area
- What’s the difference between admin_url() and get_admin_url() functions?
- How to influence the information displayed on widget inside wp-admin
- How to override admin-bar style
- TinyMCE custom styles remove class when switching styles
- How do I create a new WP admin color scheme?
- AJAX handler throws 400 (Bad request) – why?
- wp-admin page is blank
- Replacing select2 in admin backend for all selects
- difference between add_object_page and add_menu_page
- How to fix a theme with page.php Default Template that accidentally deleted?
- Target a certain page within wordpress backend (admin) i.e. Pages > About
- How can I rename the WordPress AJAX URL? [duplicate]
- How to add a column to the Trash page?
- Comments to only be seen by their author
- How to change menu icon which is overriden (i.e. by WooCommerce) [closed]
- Custom roles can’t access to wp-admin
- password protected post policy
- Removing the main link to Jetpack from the menu
- Access / Filter block variations in Gutenberg, in WordPress 5.6
- How to remove howdy dropdown menu content
- Add Featured image column into wordpress admin on pages AND posts
- Selective Product Category for Carousel
- How to force field validation first, then its values saved durning edit profile?
- Move ‘current-menu-item’ class on #adminmenu li from Posts to Pages for Taxonomy Edit Screen
- How to auto refresh when user change postcode
- Sections and tabs DRY – WordPress settings API
- Get First Child Page ID or Permalink in WordPress Admin
- Creating A New Admin Menu Tab For Theme Options
- wp-admin won’t load after setting wp-login custom url
- Wp admin – Set default value to 999 in comments
- Remove “Published On” inside wp-admin
- Where do i create my own function in wp-admin
- How to remove comment count column in Posts inside the admin dashboard?
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- Sortable column (by numbers) in admin users
- error at login page in wordpress
- Update to functions.php not showing in dashboard
- Add element to widgetpage
- Best way to disable sidebars on posts (only)?
- “options.php” not found
- How to change a specific admin label
- How to change a meta value (of a published post) after X days.?
- Block all plug-ins from initiating redirection upon activation?
- How to add custom metakey to shop_order page’s searching function?
- Unable to login after registration
- Insert Modal on user first login
- WP Enqueue Script Error
- DISABLE wordpress upgrade page
- admin-ajax.php & my wp-admin folder url showing in header
- What is wrong with functions.php? Fills error log with same error
- How to add next height number in Order Attributes inside the Add new page. [duplicate]
- Changed functions.php file and now site is blank [closed]
- Setcookie not setting cookies anywhere except admin
- How to override parent functions in child themes?
- Define page template in wp_insert_post
- How do I use the WP image functions in a page template?
- How to remove Customize from admin menu bar after WP 4.3
- Child theme functions.php do I use php open and close tags?
- why doesnt is_home() work in functions.php
- Enabling shortcodes for custom fields
- Passing variables to templates (alternatives to globalizing variables)
- Load post with a different template?
- Most efficient way to get custom database records from 20 buttons and 20 tables?
- Empty Date Returned on my function
- Woocommerce Attributes pulling in wrong data
- How to get the post_name when in preview?
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Echo tags used to describe the theme
- How to Display Frontend CSS for Administrator only
- How can I change a function in a parent theme via a child themes functions.php
- Automatically assign video ‘poster’ value to ‘filename’ for archive listing
- How do I remove the date and category form my portfolio pages
- Get list of all custom tanonomy id
- Modify post filter to set custom number of posts per page and exclude child posts
- Changing parent element’s class or style
- User function to return multiple get_post_meta()
- How can I pass a shortcode value to the head in wordpress functions.php
- Native gallery custom html output
- WordPress wraps span tags into p tags
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- How to add schema markup to WordPress menu function
- contact form in template with jquery,validate and ajax
- How to require a config file in a template and in function.php?
- Populate Product Regular Price with a calculated ACF Field Value
- Header menu aligned right on all pages except for single-post page [closed]
- How to create an array if ’empty’?
- Auto remove tags on certain date
- get_field() with ID in one signal filter not working
- i can’t use wordpress functions in ajax loaded php file
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- Adding A New Widget to WordPress Disables the Existing Widgets
- Problem in outputting shortcode
- How to get tags and categories?
- Archive.php, and post_is_in_descendant_category
- How do I access variables outside a function [closed]
- Retrieving next_post_link() and previous_post_link() in functions.php
- Get all users from role and add to dropdown (select) – wordpress, javascript
- WordPress enque the same script causes the setInterval not to work