• Hi, I’m trying to edit the header for just one landing page on a website I’m working on. We want to have a different phone number for just one page (it’s a tracking phone number), but I’m not positive on how to edit the header for just one page.

    After looking around, I’m thinking I can create an additional header.php file and then create a new template (just copy and paste everything so it all looks/functions the same) and then have this new template use the additional header.php file I created. In that new header.php file, I would just hardcode the new phone number.

    However, I can’t seem to edit the header file as easy as I thought because I can’t find the phone number…would that content be in a different file?

    If someone has a quick walk through process on how I can edit the header’s phone number for just one page, that would be great. Thank you!

    The site is https://www.calgarycarpetcleaner.com/ and it uses the Persuasion theme. Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You can create a child theme and modify probably page.php, changing
    <?php get_header(); ?>
    to something like

    <?php
    if ( is_home() ) :
    	get_header( 'home' );
    elseif ( is_404() ) :
    	get_header( '404' );
    else :
    	get_header();
    endif;
    ?>

    This page has more info on the get_header function.

    Also see this topic.

    Moderator t-p

    (@t-p)

    Thread Starter coltenv

    (@coltenv)

    Thanks Tara and jpurdy for the help, I think I’m on the right track. However, I’m still not sure where I would change the phone number…is this content usually in the header.php file? Originally I was going to create a new header.php file and do what jpurdy suggested, but I’m not sure where I would change that content. Let me know if you want to see the code for the header.php file. I can post it in pastebin if necessary. Thank you

    Thread Starter coltenv

    (@coltenv)

    Here it is anyway. Thanks! https://pastebin.com/uTeVjQBY

    Thanks for that code, I compared the html in the header file to your site, it looks like that telephone numbers html(and all the “HTML Extras”) are printed from the mysite_before_header(); function. Your next step would be to go through your themes files, open any that look like they might have a lot of template functions in them, and search for that function. It sometimes takes a lot of digging to find those.

    Once you find that function, your theme ‘might’ allow it to be declared by a child theme if it is in something like this:

    if( !function_exists( 'function_name' ))

    Otherwise you will need to copy that file into your child theme end modify it there. I don’t suggest modifying the parent theme because any updates will revert your code change back to the authors code.

    Thread Starter coltenv

    (@coltenv)

    Could I essentially just hardcode the new phone number in the new header.php file I created and delete that function call? And then just do

    <?php
    if ( is_secondary() ) :
    	get_header( 'secondary' );
    else :
    	get_header();
    endif;
    ?>

    secondary-header.php is the name of the new file I created

    You could do that, and make it print out the same html the other had printed. Just replace mysite_before_header(); with the html it printed out.

    If the mysite_before_header(); function had any additional functionality though that will be lost. My thought would be replacing it would most likely be fine, and if finding that function were too difficult that is what I would do. I have done it in the past.

    Thread Starter coltenv

    (@coltenv)

    Thanks jpurdy, I was able to get it to work. For future reference, how were you able to know the exact line of PHP that was used for the mysite_before_header(); ? Because that was the line affecting the html, but how did you find that out? Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Change the header for only one page on a website’ is closed to new replies.