Thursday 12 February 2015

Adding a logo uploader to your WordPress theme with the Theme Customizer



Adding a logo uploader to your WordPress theme with the Theme Customizer

Here Simple code of adding logo in wordpress theme 

i am write this code.

some refrence site for it more detail 

2)http://themefoundation.com/wordpress-theme-customizer/



first add this code in your theme functions.php in wordpress


function myblog_customize_register( $wp_customize ){
    
   $wp_customize->add_section( 'myblog_logo_section' , array(
    'title'       => __( 'Logo', 'myblog' ),
    'priority'    => 30,
    'description' => 'Upload a logo to replace the default site name and description in the header',
) );

$wp_customize->add_setting( 'myblog_logo' );

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'themeslug_logo', array(
    'label'    => __( 'Logo', 'myblog' ),
    'section'  => 'myblog_logo_section',
    'settings' => 'myblog_logo',
) ) );
    
}
add_action('customize_register','myblog_customize_register');

after check in wordpress admin it will create logo in theme customizer

for display logo add below code in header.php in your theme

<?php
 if ( get_theme_mod( 'myblog_logo' ) ) {  ?>
    <div class='site-logo'>
        <a href='<?php echo esc_url( home_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>' rel='home'><img src='<?php echo esc_url( get_theme_mod( 'myblog_logo' ) ); ?>' alt='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>'></a>
    </div>
<?php } else { ?>
    <hgroup>
        <h1 class='site-title'><a href='<?php echo esc_url( home_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>' rel='home'><?php bloginfo( 'name' ); ?></a></h1>
        <h2 class='site-description'><?php bloginfo( 'description' ); ?></h2>
    </hgroup>
<?php } ?>

check reference site and get it how it work.



No comments:

Post a Comment

Thank You For Comment