Codementor Events

Add custom css and javascript on WordPress Head on fly.

Published Jul 11, 2018Last updated Jul 13, 2018

Hi everyone its my first post here so i gonna share some simple and very interesting thing about wordpress.As everyone knows that WordPress is very popular CMS over the internet and many websites running on this system,i have seen in many website , people need some custom css and javascript code to wordpress system that will very helpful, when you want override some css and javascript function, We can do this using WordPress in-built (wp_head) hooks.
Let me explain how we can add custom css and javascript code in any theme of wordpress?
There are some steps you can follow,

  1. Go to theme folder, theme location /root/path/wp-content/themes/{Your Running Theme name}

  2. Using FTP or Cpanel(click on filemanager) then you can see same path like above and open theme's functions.php and open in any text editor well i use notepad++ so i use for editing files.

  3. When you open the file go to the end of the file and add my code that i am putting here.

add_action('wp_head','add_my_custom_scripts_styles');
function add_my_custom_scripts_styles(){
?>
<!--   Add style tag for custom style  -->
<style>Add your css code here </style>
<!-- Add script tag for custom javascript code -->
<script> Add your javascript code</script>
<?php }
  1. Thats it , You can see in view source of current page your custom code will be added in wp head section.
    I think its very simple to understand and do in functions.php of theme so if you have any questions , just let me know.
    Happy Coding.....
Discover and read more posts from Neeraj Chaturvedi
get started
post commentsBe the first to share your opinion
Rahul Gupta
6 years ago

How to add loder icon with place order button in checkout page in woocommerce without core file of woocommerce. If you know please tell me.

Thanks

Neeraj Chaturvedi
6 years ago

Yes you can do this without touch woocommerce core files, You need to add controll checkout button on click or submit event in jQuery then you can use your loader icon when some click on check out button.
you can hide and show this functionality.
Thanks

Show more replies