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
- How to install Segment on WordPress without a plugin
- 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
- Functions.php code that only runs on localhost?
- hook a functions to change wp-config from functions.php
- Check if the user has explicitly set an excerpt
- Slugs as breadcrumbs for Pages
- Shortcode with custom content attribute?
- Add a Post Thumbnail to an RSS Feed with custom size
- Automatically add author’s name to post_tag
- Print Dashboard menu name and link
- Develop function get_template_part in functions.php
- Ajaxing function in widget class
- wp_register_script(… $in_footer = true) not working
- Restore Image Title Text
- remove wp floating submenu in wp dashboard
- Output and filter data from a XML url
- How do I create a function that simulate the click on Update button for all posts?
- How to change menu labels
- WordPress listen to $_POST in functions.php
- Add Element as a Filter to the_content
- Can’t properly set the_title add_filter to show short_URL
- WordPress function, Run using Crontab
- Tags break custom Excerpt function
- Can set_post_thumbnail be used to remove a thumbnail?
- issue with if/elseif in_array inside foreach loop display only one post
- Fail to get the total number of posts
- Call two different function.js depending on page
- Display a random tag but using cron to control frequency of change
- resizing of thumbnails not working
- How Do I include/Import a Custom Widget from the Parent theme into My Child Theme?
- Need To Resize Images Exactly Without Losing Image Details
- the_date() and the_time() functions display actual date an time instead of published date and time
- Can’t load assets
- Warning and fatal error
- Including admin-options.php file in Child Themes
- Adding an IF ELSE to a function
- wordpress ajax is not working for dropdown selection
- Providing fallback function and allow override by plugin
- is_page_template wont allow me to enqueue scripts
- Updating site content after an AJAX call without a page reload
- need help with ‘… read more’ excerpt in functions.php
- jQuery HoverIntent is not a function
- Use $_POST[‘value’] inside functions.php
- get_footer can’t find any variables set in functions.php
- How to hook wp_mail to add a custom email as BCC for each sent email?
- Add URL parameter to nav links based on domain