ToujouAya
ToujouAya

Reputation: 593

Why some of Wordpress theme doesn't have Header Image Section

I am new in Wordpress. I want to know. Why some of the Wordpress themes don't have header image section in Theme customize? How to add this section to the theme customizer? Is there any way to do it

enter image description here

And one question. How can I modify the upload file image in the theme customizer? I want to add more field and change the crop size

enter image description here

Upvotes: 0

Views: 903

Answers (2)

Edwin Castañeda
Edwin Castañeda

Reputation: 176

For the first you need to add support to custom-header.

See the codex: https://developer.wordpress.org/themes/functionality/custom-headers/

Obviously, you need to create a php file with the code and include in the functions.php or add the code directly to your functions.php file.

    function themename_custom_header_setup() {
    $defaults = array(
        // Default Header Image to display
        'default-image'         => get_template_directory_uri() . '/images/headers/default.jpg',
        // Display the header text along with the image
        'header-text'           => false,
        // Header text color default
        'default-text-color'        => '000',
        // Header image width (in pixels)
        'width'             => 1000,
        // Header image height (in pixels)
        'height'            => 198,
        // Header image random rotation default
        'random-default'        => false,
        // Enable upload of image file in admin 
        'uploads'       => false,
        // function to be called in theme head section
        'wp-head-callback'      => 'wphead_cb',
        //  function to be called in preview page head section
        'admin-head-callback'       => 'adminhead_cb',
        // function to produce preview markup in the admin screen
        'admin-preview-callback'    => 'adminpreview_cb',
        );
}
add_action( 'after_setup_theme', 'themename_custom_header_setup' );

Then on your header.php get the image and put in where you want it.

<?php if ( get_header_image() ) : ?>
<div id="site-header">
    <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
        <img src="<?php header_image(); ?>" width="<?php echo absint( get_custom_header()->width ); ?>" height="<?php echo absint( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
    </a>
</div>

*functions.php is on the root of your theme folder, if your theme uses a "child-theme" please use this folder to do the changes.

And answering your question, when you upload the image you can crop and resize the image. Wordpress cannot edit photos as an editor, only resize and crop.

Upvotes: 1

Aakanksh Patel
Aakanksh Patel

Reputation: 623

this depends on the WordPress theme developer how they design and develop themes but you can achieve this by adding your own option like (image, textarea , input) fields in the customizer area.

Here is the example add this code in a function.php file

// Header Logo
    function add_logo_customizer($wp_customize) {
    $wp_customize->add_section(
            'logo_image',
            array(
                'title' => 'Logo Image',
                'priority' => 45,
            )
        );
        $wp_customize->add_setting( 'Logo-upload' );
        $wp_customize->add_control(
            new WP_Customize_Image_Control(
                $wp_customize,
                'lp-image_selector',
                array(
                    'label' => 'Logo Image',
                    'section' => 'logo_image',
                    'settings' => 'Logo-upload'
                )
            )
        );
    }
    add_action('customize_register', 'add_logo_customizer');

and you can call it as <?php echo get_theme_mod( 'Logo-upload' ); ?>

The above code is tested and it works

enter image description here

Upvotes: 1

Related Questions