Drupal 7 Adding Classname to the body tag


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. function ivorypearl_preprocess_html(&$variables, $hook) {
  3. // Classes for body element. Allows advanced theming based on context
  4. // (home page, node of certain type, etc.)
  5. if (!$variables['is_front']) {
  6. // Add unique class for each page.
  7. $path = drupal_get_path_alias($_GET['q']);
  8. // Add unique class for each website section.
  9. list($section, ) = explode('/', $path, 2);
  10. if (arg(0) == 'node') {
  11. if (arg(1) == 'add') {
  12. $section = 'node-add';
  13. }
  14. elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
  15. $section = 'node-' . arg(2);
  16. }
  17. }
  18. $variables['classes_array'][] = drupal_html_class('section-' . $section);
  19. }
  20. if (theme_get_setting('ivorypearl_wireframes')) {
  21. $variables['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
  22. }
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.