{"id":3261,"date":"2014-06-23T21:58:03","date_gmt":"2014-06-23T21:58:03","guid":{"rendered":"http:\/\/webninjataylor.com\/library\/?p=3261"},"modified":"2014-06-24T20:45:14","modified_gmt":"2014-06-24T20:45:14","slug":"add-css-and-js-properly-to-a-wordpress-theme","status":"publish","type":"post","link":"https:\/\/webninjataylor.com\/library\/add-css-and-js-properly-to-a-wordpress-theme\/","title":{"rendered":"The Proper Way to Add CSS and JS to a WordPress Theme"},"content":{"rendered":"<p>Add this to <strong>functions.php<\/strong> for JS and CSS. \u00a0Check out the WordPress Codex for available parameters and info on using the &#8216;$&#8217; namespace for jQuery.<\/p>\n<pre>&lt;?php\r\n    function wnt_styles(){\r\n        \/\/ STYLES\r\n        wp_register_style('bootstrapcss', get_template_directory_uri() . '\/css\/bootstrap.css', array(), '20140529', 'all' );\r\n        wp_enqueue_style('bootstrapcss');\r\n    }\r\n    add_action('wp_enqueue_scripts', 'wnt_styles');\r\n    wp_enqueue_script('jquery');  \/\/ This is all that's needed for jQuery since WordPress already has it registered as one of the core libraries\r\n    function wnt_scripts(){\r\n        \/\/ Register the script like this for a theme:\r\n        wp_register_script('wp-test-inclusion', get_template_directory_uri() . '\/js\/wp.test.inclusion.js', array('jquery'));\r\n        \/\/ For either a plugin or a theme, you can then enqueue the script:\r\n        wp_enqueue_script('wp-test-inclusion');\r\n    }\r\n    add_action('wp_enqueue_scripts', 'wnt_scripts');\r\n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Add this to functions.php for JS and CSS. \u00a0Check out the WordPress Codex for available parameters and info on using the &#8216;$&#8217; namespace for jQuery. &lt;?php function wnt_styles(){ \/\/ STYLES wp_register_style(&#8216;bootstrapcss&#8217;, get_template_directory_uri() . &#8216;\/css\/bootstrap.css&#8217;, array(), &#8216;20140529&#8217;, &#8216;all&#8217; ); wp_enqueue_style(&#8216;bootstrapcss&#8217;); } add_action(&#8216;wp_enqueue_scripts&#8217;, &#8216;wnt_styles&#8217;); wp_enqueue_script(&#8216;jquery&#8217;); \/\/ This is all that&#8217;s needed for jQuery since WordPress already has [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[144],"tags":[19,9,5],"class_list":["post-3261","post","type-post","status-publish","format-standard","hentry","category-web-shots","tag-css","tag-javascript","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/comments?post=3261"}],"version-history":[{"count":5,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3261\/revisions"}],"predecessor-version":[{"id":3317,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/3261\/revisions\/3317"}],"wp:attachment":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/media?parent=3261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/categories?post=3261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/tags?post=3261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}