I want to change my header (all header : logo + menu) on specific pages of my wordpress.
EDIT : I didn't precise something important, in my mind, I woudl like to change the header on specific page AND tagged post.
Example : header test on page id 4, and post 3,4 & 5 wich are tag "test".
How can I manage that easily ?
I tried some plugins without success :
WP Display Header
Page Specific Menu Items
Menu Swapper
I have the idea to change it with an if statement, but I'm worried about maintaining this code in time (I'm thinking about WordPress or Theme updates).
Have you already do that ?
Thanks a lot,
<?php if(is_page(<page id>)) { ?>
--------- Header 1 -----
<?php } else { ?>
--------- Header 2 --------
<?php } ?>
Add this code according to your header sections in header.php of your theme.
When you use get_header() an optional parameter is the name of the header, you can see this in:
https://developer.wordpress.org/reference/functions/get_header/
You need to create, for instance, header-another.php and put the code in it, after this only need calls get_header('another').
Probabilly you need to create a custom template for the page that has a different header and call get_header('another') instead get_header() in it.
There are some bullet points you have to know about using different on different page.
first if you want to use different headers on different pages for example you want header(one) on productOne-page.php and header(two) on productTwo.php file.
For this First you have to create two header files namely header-one.php and header-two.php.
now when you call header(one) in your productOne-page.php file you call it like:- get_header('one');
and when you call header(two) in your productTwo-page.php file you call it like:- get_header('two');
and at last if you need to call default header in any file you can call just get_header();
summery: just call different header with their name after hyphen(-) in file name i.e. get_header('Custom Header Name');
I hope it will help you.:)
I'm using the plugin Page Menu (by Rohit Kumar) to change the menu and the Haninder Singh solution to change the header and it work perfect.
Related
I am using a custom template named "full_width" which I downloaded from this tutorial/blog post: https://www.wpbasics.org/advanced-custom-fields-custom-front-page/
In this link you will find both, the php and css code.
Everything works fine but the fact that I cannot remove the main header (what I called Header "1" in the picture below).
here you can see what I refer to when I write Header "1"
I want to remove the Header 1 because I already have a second header (header 2 of the picture), which was already built in my website from my developer.
I thought was enough to replace the get_header() line at the end of the php code with the one which recalls my header "2". However it does not work.
At the moment, I changed the last part of the template code, by simply adding a new line (the second one) as follow:
get_header();
get_template_part('parts/header'); the_post();
do_action('full_width_content');
get_footer();
Obviously it will show the both headers. In fact, this is how the page currently looks like.
If I delete the "get_header()" line, the layout of the page will turn like this (a mess)
Can someone guide me to a solution. Let me clarify that I know nothing about coding, nor PHP, neither CSS. I am not a developer. Therefore I would need a ready to go solution which I simply need to copy and paste into my website.
could it be as easy a
get_template_part('parts/header'); the_post();
do_action('full_width_content');
get_footer();
My theme doesn't support custom headers when trying via a plugin so i was wondering if there was another way around this?
Tested WP Header Images by adding some code in header.php, but doesn't seem to work.
Tried the plugin Unique Headers, but it pops a message that the theme doesn't provide custom header when activating it.
By default, there is the same header for every WordPress page of the site. But how to call different header in WordPress? For that, create a new header-your page.php file i.e create a header file for the page you want a different header. Suppose you want a different header on about page. Create a header-about.php file and keep it in the Theme folder.
Then, go in page template file say page.php and replace the header code with
<?php
if(is_page(about))
{
get_header('about');
}
else
{
get_header();
}
wp_head();
?>
You can see, is_page is used to check the page id for “about” page. The function get_header is used for calling a new header file. Simply, the above code is informing WordPress that if someone opens the page, which is ‘about’ then WordPress will display a file called header-about.php if it is existing. If not, then WordPress will render the default header file.
This way, you can call different WordPress headers on different pages.
I need to add a header Access-Control-Allow-Origin: * into one of my template files. How would I do this I would like it to be for just this specific template so that its not site wide,
I think you're looking for is_page_template();
<?php
if(is_page_template('your-page-template.php')) { //Change this to the path to your wordpress template
//Add your code here...
} ?>
you can create a custom template page and call the custom Header on this template.
To create a page and apply a page template
use this code to create page template
First you need to have a single page. There are several ways to do it, one is to create a page in wordpress, then use the ID and create a file page-ID.php in the theme folder. Other way is to create a template file which you can select from the side menu in the wordpress editor.
In that page, you can add the php header and the code you want to show.
What I would like to do is have a different header (not header image) appear on each page of my WordPress website, for example on the about page I'd like the header to be blue with text and on the home page i'd like the header to be red with text. I have search google for answers but the posts that come up are very older and show methods on how to replace the header image on each page within wordpress.
Would I do something like the below script and place it in function.php? (I'm newbie to WordPress)
<?php if ( is_about_page() ) {
if ( function_exists( 'about-header.php' ) ) {
}
} ?>
You could probably use the function get_header() (https://codex.wordpress.org/Function_Reference/get_header) in combination with the page name ($pagename global WP variable), by doing something like this:
Apart from using the main - default header in header.php, create your custom header PHP files following the name convention header-{name}.php, in which you put your header specific code.
Then, in page.php you can do:
get_header($pagename);
This will probably call the appropriate header based on your page name.
I am trying to modify a theme on wordpress. The theme shows a slider on the front page, which reads from the featured.php file.
I have gone into the featured.php and removed all the PHP code. I can inject my custom HTML into the featured.php and the pages display properly, however I want the page to display from a wordpress page.
So i tried to:
<?php
$html = file_get_contents('http://www.mydomain.com/homepage-featured');
?>
The above link corresponds to a page i created in wordpress. So i want to be able to inject my HTML into that page and then when you load my homepage, the PHP tells the browser to display the contents of this URL.
The above code doesn't work.
Thanks for the help.
file_get_contents() - as its name suggests - reads a file in but does not print it. You need to echo your $html variable. A better way is to use require() or include() but if I were you I would put my custom file on the same server so that way you don't have to use the file from a remote location thus sparing network traffic.
I think you have better to use the include function.
The file_get_contents you are using would generate an HTTP request, so it would make your script slower. I think it would be a good idea to put the HTML file on the same server if possible.
Have you tried
<?php
require('http://www.mydomain.com/homepage-featured');
?>
If my understanding is correct, you are trying to use a template (featured.php) for a different page other than the front page.
To do so, just change the Page Template of the page(the separate page which is # www.url.com/myhomepage). You can change this # Dashboard > Pages (Click Edit link in the required page) > Edit Page > Page Attributes meta box (available in the rightside below Publish) > Template. Change the template of this page to "Featured".
(I assume that your code in file feature.php has Template Name: Featured at the top)