Archived topic
Change Site Header and Title - based on page
16 replies · Started by Anonymous on May 22, 2015
Is it possible to change the site header and title for individual pages?
(Replace the sitewide header and title)
I received a note with some of the plugins that a custom header is not supported with this theme.
Hi there,
This is possible using GP Hooks.
I explain how to achieve this here: http://generatepress.com/forums/topic/changing-headers-or-deleting-headers/#post-98390
We support a custom header through the Customizer (Customize > Header Content) instead of the old WordPress way, which is being fazed out in favor of the Customizer.
Let me know if you need more info! :)
Thank you for the link.
I understand how that could work, but if you had a large number of pages that code could get quite tedious.
I was hoping for a compatible plugin where on each edit page screen you could upload the header image for that page, and change the page title.
Are you aware of such a plugin?
I'll take a look around and will get back to you :)
Sorry for not getting back to you sooner!
I've come up with a pretty simply solution that doesn't involve any plugins etc..
1. On your page, click the "Screen Options" tab at the top right of the page. Make sure the "Custom Fields" checkbox is checked.
2. Now look for the "Custom Fields" metabox - click "Enter new".
3. Under "Name", add: custom_header
4. Under "Value", enter the URL to your image.
5. Now in GP Hooks, in the "Before Header Content" hook, add this:
<?php
global $post;
$image = get_post_meta($post->ID, 'custom_header', true);
if ( ! empty( $image ) ) : ?>
<img src="<?php echo $image; ?>" alt="" />
<?php else : ?>
<img src="URL TO MY DEFAULT LOGO" alt="" />
<?php endif; ?>
Be sure to check the "Execute PHP" checkbox.
This will check to see if we have a "custom_header" attribute on the current page - if we do, we'll display that image. If we don't, we'll display the default logo.
Once you've added the "custom_header" name, you'll be able to select it from the dropdown on all future pages (instead of having to click "Enter new".
After the initial setup, this will be much easier than my initial code.
Let me know if you have any questions :)
Hi
I'm creating a WP site using GeneratePress. I have bought your customizing addons - they're great :-)
I am aiming to replace the site http://www.brokenbog.com with the WP site eventually. Could you give me some tips on how to create a header with writing either side of the banner image (see http://www.brokenbog.com) without the text being part of the graphic?
Thanks
Hi Annie,
You could use GP Hooks for this with our grid system. You would put this in the Before Header Content area:
<div class="grid-20">
Text in here
</div>
<div class="grid-60">
<img src="URL IN TO HEADER IN HERE" alt="" />
</div>
<div class="grid-20">
Text in here
</div>
Then you would make sure your site title and tagline are disabled in "Customize > Header Content".
Let me know if this helps or not :)
Hi Ben
I've just tried the solution posted above - #111841
I'm finding that it works in showing the new logo, however it now shows both (the original is underneath) Can you amend the php to hide the original if custom_header is showing. If it's a simple as that. (I'm not a coder)
Thanks,
Lee
Hi Lee,
Any chance you can open up a new topic with details specific to what you're wanting to do exactly?
Thanks!
Hi Tom (not Ben,:$), thanks for the response. There wasn't an issue really.
Basically, I wanted to have a different logo showing on certain pages of my website.
Your add custom_header code for GP hook worked, however I was seeing 2 logos on each page. It was simply a case of removing the logo from the customize>site identity section.
Thanks for an awesome theme!
No problem! Glad you got it working :)
Hi Tom,
In order to add some custom code / functionality to just one page of my site, I've set up a custom_header under the “Custom Fields” metabox together with the following code added to the header.php file (just above the closing </head> tag):
<?php if (is_page()) {
if ($custom_header = get_post_meta($post->ID, 'custom_header', true)) {
echo $custom_header;
}
}
?>
This works fine, but I'd rather place the above code within a hook rather than editing the header.php file. Please advise which hook I should use.
Many thanks for your help.
Hi there,
I think wp_head is what you are looking for:
https://docs.generatepress.com/article/wp-head/
https://docs.generatepress.com/article/hooks-overview/
Hi Leo,
Thanks for your reply. I've tried adding the code to wp_head, but it doesn't seem to be working (i.e. there's just a blank space on the page now).
It was working fine when I had the lines of code inserted directly in header.php, so I'm guessing it's not executing when included in wp_head? I've double checked and I do have the Execute PHP box ticked (and disable hook is empty i.e. unticked). Please advise whether my code below is correct for inclusion in wp_head:
<?php if (is_page()) {
if ($custom_header = get_post_meta($post->ID, ‘custom_header’, true)) {
echo $custom_header;
}
}
?>
Many thanks
Hmm the code looks good to me.
Can you actually start a topic and include a link to your site in the private URL field?