Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. function hmbl_theme_color() {
  3.     global $post;
  4.  
  5.     $color = hmbl_recursive_find_color($post->ID);
  6.    
  7.     if ($color != false) : ?>
  8.  
  9.         <style type="text/css" media="screen">
  10.             .theme-color {
  11.                 color: <?php echo $color ?>;
  12.             }
  13.             .theme-background-color {
  14.                 background-color: <?php echo $color ?>;
  15.             }
  16.             .theme-border-color {
  17.                 border-color: <?php echo $color ?>;
  18.             }
  19.         </style>
  20.  
  21.     <?php endif;
  22. }
  23. add_action('wp_head', 'hmbl_theme_color');
  24.  
  25. function hmbl_recursive_find_color($post_id) {
  26.     $use_color = get_field('theme_color_active', $post_id);
  27.    
  28.     if ($use_color == true) {
  29.         return get_field('theme_color', $post_id);
  30.     } else {
  31.         $post = get_post($post_id);
  32.         if (isset($post->post_parent) && $post->post_parent != 0) {
  33.             return hmbl_recursive_find_color($post->post_parent);
  34.         } else {
  35.             return false;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement