{"id":727,"date":"2014-05-01T00:14:43","date_gmt":"2014-05-01T00:14:43","guid":{"rendered":"http:\/\/www.advancedwebhelp.com\/blog\/?p=727"},"modified":"2014-05-01T00:22:20","modified_gmt":"2014-05-01T00:22:20","slug":"drupal-7-how-to-assign-custom-css-and-js-by-node","status":"publish","type":"post","link":"https:\/\/www.advancedwebhelp.com\/blog\/2014\/drupal-7-how-to-assign-custom-css-and-js-by-node","title":{"rendered":"Drupal 7; How to assign custom CSS and JS by node"},"content":{"rendered":"<p>If you need to have custom CSS or JS for a node, it is easy to set up.&nbsp;&nbsp; This can be setup via the template.php file.&nbsp;&nbsp; To customize available CSS or JS via template.php, modify the THEME_preprocess_node.&nbsp; For example, if you have a special node type called &#8220;directory&#8221; in a theme called &#8220;boulder,&#8221; add the following code to your boulder_preprocess_node function.<\/p>\n<pre><code>\r\n\r\n  function boulder_preprocess_node(&$variables) {\r\n    if ($variables['view_mode'] == 'full') {\r\n      $node =& $variables['node'];\r\n      if ($node->type == 'directory') {\r\n        $path = drupal_get_path('theme', 'boulder');\r\n        drupal_add_css($path . '\/CSS\/directory.css');\r\n        drupal_add_js($path . '\/js\/directory.js', \r\n            array('type' => 'file', 'scope' => 'header'));\r\n      }\r\n    }\r\n  }\r\n\r\n<\/code><\/pre>\n<p style=\"clear: both ; \">I love this. It&#8217;s quick, easy and very useful.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need to have custom CSS or JS for a node, it is easy to set up.&nbsp;&nbsp; This can be setup via the template.php file.&nbsp;&nbsp; To customize available CSS or JS via template.php, modify the THEME_preprocess_node.&nbsp; For example, if you have a special node type called &#8220;directory&#8221; in a theme called &#8220;boulder,&#8221; add the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7,16,13],"tags":[],"class_list":["post-727","post","type-post","status-publish","format-standard","hentry","category-css","category-drupal","category-javascript","category-jquery"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts\/727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/comments?post=727"}],"version-history":[{"count":2,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts\/727\/revisions"}],"predecessor-version":[{"id":731,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts\/727\/revisions\/731"}],"wp:attachment":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/media?parent=727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/categories?post=727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/tags?post=727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}