2

I am developing a WordPress theme and would like to make use of a custom header on a the homepage (I'm using a custom page template).

I would like this header to not include an image, but rather an <h1> and <h2> tag, and a link.

So my question is the following - how do I go about providing users with the facility to update the headings and the link in the header from the admin backend? Would add_theme_support( 'custom-header' ); be suitable for this since I need to add my own fields? And how would I go about completely disabling support for the image and showing the text in my page template?

2

File: functions.php

It's as easy as adding this to your functions.php file (of course having $wpse67109 set).

add_theme_support( 'custom-header', $wpse67109_defaults );

File: index.php or any other template

Simply don't add the whole get_head_image() and get_custom_header()->foo stuff anywhere.

Your headline template part could look like the following example:

<header>
    <hgroup>
        <h1 class="site-title">
            <?php
            if ( display_header_text() )
            {
                printf(
                     '<a href="%s" title="%s" rel="home">%s</a>'
                    ,esc_url( home_url( '/' ) )
                    ,esc_attr( get_bloginfo( 'name', 'display' ) )
                    ,get_bloginfo( 'name' )
                );
            } 
            ?>
        </h1>
        <?php if ( '' !== get_bloginfo( 'description' ) ) : ?>
            <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
        <?php endif; ?>
    </hgroup>
</header>
| improve this answer | |
  • 1
    Thank you for your reply. Ok, I'll give this a shot - just to clarify though, '$wpse67109_defaults' is the name of the array you used to set the settings for the custom header right? – Ian Muscat Oct 4 '12 at 11:52
  • @IanMuscat Right. I just prefix such stuff for questions in here. – kaiser Oct 4 '12 at 11:54
  • Hi, I tried out the example you provided me with - However I didn't get as far as I intended... While the code you gave above removes the image, I am still confused as to how I should insert my custom fields into the header area - I need to give the functionality to users to change the content that's in <h1> and <h2>. I found this tutorial - I'll give it a try and see where it takes me... – Ian Muscat Oct 4 '12 at 12:28
  • @IanMuscat What? Why? Nooo°°.... ! Just use the theme customizer with above code ↑. It's as easy as that. – kaiser Oct 4 '12 at 12:32
  • I must be missing something, sorry for being so green, I'm sort of new to this... I'm not sure if I explained myself clearly... My objective is to have the whole default header image with three textboxes in the admin - one that will contain the h1, one with the h2 and another with the link - that way a user can edit the text from the back-end and it will show up dynamically on the front-end... Is this achievable code you posted above? - Once again, thanks so much for your help! – Ian Muscat Oct 4 '12 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.