• Daer community, I am very new to WP and am currently learning to build customized websites via WP. Right now, I am struggling with implementing a custom header showing a movie (using the “understrap“-theme).
    I first installed the “understrap“-theme and then the “understrap-child“-theme an activated the latter one. Regarding to “https://codex.ww.wp.xz.cn/Custom_Headers”, I added the following lines to “understrap-child/functions.php”:

    — edits to “functions.php” in “understrap-child/functions.php”/start—

    register_default_headers( $headers );
    $defaults = array(
    	'default-image'          => get_template_directory_uri() . '/images/header.jpg',
    	'width'                  => 300,
    	'height'                 => 200,
    	'flex-height'            => false,
    	'flex-width'             => false,
    	'uploads'                => true,
    	'random-default'         => false,
    	'header-text'            => true,
    	'default-text-color'     => '',
    	'wp-head-callback'       => '',
    	'admin-head-callback'    => '',
    	'admin-preview-callback' => '',
    );
    add_theme_support( 'custom-header', $defaults );

    —-edits to “functions.php” in “understrap-child/functions.php”/end————-

    After reloading my WP-site, under “Appearance/customize” the “Header Image” option showed up and I uploaded a respective image. Then, I copied the “header.php” from “/understrap” to “/understrap-child” and added after “</nav><!– .site-navigation –>”:

    —— edits to “header.php” in “understrap-child/functions.php”/start————-
    <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
    ——– edits to “header.php” in “understrap-child/functions.php”/end———

    … the header image shows up, but I cant change the width when changing the width from 300 to exp. 800. Then, regarding to “https://developer.ww.wp.xz.cn/themes/functionality/custom-headers/&#8221;, I added the following lines to “understrap-child/functions.php”:

    ——- additions to “functions.php” in “understrap-child/functions.php”/start——

    function understrap_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', 'understrap_custom_header_setup' );

    —- additions to “functions.php” in “understrap-child/functions.php”/end——-

    This didn’t have any effects on the width of the image either. I think, my very basic problem is that I am not experienced with WPs php-framework… but I am willing to learn…. maybe someone could help me with this??? Thx a lot!

Viewing 1 replies (of 1 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Greetings!

    I know this might be a little odd but have you tried setting the priority to something higher in the child theme? Not sure if you are aware of the developer docs for the add_action hook but here it is: https://developer.ww.wp.xz.cn/reference/functions/add_action/

    The quirky part about child themes is that their functions file will load before the parent theme. Then again WordPress will use child theme files first if they exist too and then fallback to the parent. Sorry, I ramble on at times. Themes are weird but cool too. 😂

    Try setting the priority to something like 15 and let us know if that helps. 🙂

Viewing 1 replies (of 1 total)

The topic ‘Implementing a custom header via php’ is closed to new replies.