If you are looking for how to add that google analytics script, google tag manager script or hot jar script to your WordPress website. Then you don’t need to add those plugins, because adding plugins is easy but you need to regularly update them. As hackers use plugins mostly if they are not maintained by the author. Also, you don’t need all those extra lines of code to add your code. With the help of just a few lines, you can add your script and no need to maintain it. You can use your functions.php file and paste the code given below:
function my_custom_javascript_code_in_site_head() {
?>
<script>
// replace this with your javascript code here
</script>
<?php
}
add_action('wp_head', 'my_custom_javascript_code_in_site_head');
Where will I find functions.php? For this, you need to access your server files:
- Use an FTP client like FileZilla or
- If your hosting provider gave you access to Cpanel then you can directly access the files using it.
Whatever your case, you need to follow this path to find your functions.php
/home/public_html/wp-content/themes/{theme-name-child}/functions.php
Leave comments if you have any questions I will try my best to answer.
Thanks for Reading!