Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

How to make call to a function if we don't have custom header ?

Here, In this code for applying the styles to h1 we're using function wpt_style_header which is get a call through custom header (theme-support ) but In case, If we don't have custom header than how we execute that function for applying all the styles of h1.

  // Add H1 Style Settings
  $wp_customize->add_section( 'h1_styles' , array(
    'title'      => __('H1 Styles','wptthemecustomizer'), 
    'panel'      => 'design_settings',
    'priority'   => 100    
  ) );  
  $wp_customize->add_setting(
      'wpt_h1_color',
      array(
          'default'         => '#222222',
          'transport'       => 'postMessage'
      )
  );
  $wp_customize->add_control(
       new WP_Customize_Color_Control(
           $wp_customize,
           'custom_h1_color',
           array(
               'label'      => __( 'Color', 'wptthemecustomizer' ),
               'section'    => 'h1_styles',
               'settings'   => 'wpt_h1_color' 
           )
       )
   ); 
  $wp_customize->add_setting(
      'wpt_h1_font_size',
      array(
          'default'         => '24px',
          'transport'       => 'postMessage'
      )
  );
  $wp_customize->add_control(
        new WP_Customize_Control(
            $wp_customize,
            'custom_h1_font_size',
            array(
                'label'          => __( 'Font Size', 'wptthemecustomizer' ),
                'section'        => 'h1_styles',
                'settings'       => 'wpt_h1_font_size',
                'type'           => 'select',
                'choices'        => array(
                  '22'   => '22px',
                  '28'   => '28px',
                  '32'   => '32px',
                  '42'   => '42px'
                )
            )
        )       
   );   

// Add theme support for Custom Header Image
$defaults = array(
  'default-image'          => get_template_directory_uri() . '/images/header.png', 
  'default-text-color'     => '#36b55c',
  'header-text'            => true,
  'uploads'                => true,
  'wp-head-callback'       => 'wpt_style_header'
);
add_theme_support( 'custom-header', $defaults );


// Callback function for updating header styles
function wpt_style_header() {

  $text_color = get_header_textcolor();

  ?>

  <style type="text/css">

  #header .site-title a {
    color: #<?php echo esc_attr( $text_color ); ?>;
  }

  <?php if(display_header_text() != true): ?>
  .site-title, .site-description {
    display: none;
  } 
  <?php endif; ?>

  h1 {
    font-size: <?php echo get_theme_mod('wpt_h1_font_size'); ?>;
  }
  h1 a {
    color: <?php echo get_theme_mod('wpt_h1_color'); ?>;
  }


  </style>
  <?php 

}