Welcome to WebmasterWorld Guest from 18.204.48.40

Forum Moderators: rogerd & travelin cat

WordPress - How to Edit <head>?

     
7:00 pm on Mar 15, 2019 (gmt 0)

New User from PL 

joined:Mar 15, 2019
posts:1
votes: 0


How do I edit the head section of a subpage?
12:23 pm on Mar 16, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4504
votes: 347


Hi Cymes_Poznan and Welcome to WebmasterWorld [webmasterworld.com]

The Head section of any WordPress page is going to be difficult to edit because all pages use the same template. It depends on what you wish to edit. Some meta tags in the head section can be controlled using plugins.

If you were to edit the header template of your WordPress theme it would be editing every page on your WP site. IF the edit you wanted to make was for every page on that WP site, you should create a child theme to edit or the next update could possibly overwrite your edit.

WordPress uses various components to present each page which is why some plugins can be very important as a means to adjust certain components.
8:25 pm on Mar 16, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 29, 2005
posts:10450
votes: 1087


Is the sub page that specific it needs a new head(er) that h1 can't handle?

What I mean is it that different the embedded header no longer fits with your site/presentation?
9:23 am on Mar 19, 2019 (gmt 0)

New User from US 

joined:Mar 13, 2019
posts: 3
votes: 0


Hello,

To edit the <head> section you need to go to below path in Wordpress admin.
Dashboard --> Mouse over on "Appearance" in the left panel --> Click on "Editor".

You will find several files in the right panel displayed in list view. Search for header.php. You will find the <head> section in this file.

But this file is common to home page as well as inner pages. So you need to use if else condition so that the modification you want to add work only for inner pages.
<?php if ( is_front_page() ) { ?>

<? } else { ?>
Place your code here... to display only in sub pages
<?php } ?>

Hope,you will find the above explanation helpful.
2:26 pm on Mar 19, 2019 (gmt 0)

Preferred Member from CA 

Top Contributors Of The Month

joined:Feb 7, 2017
posts:575
votes: 59


If you have a child theme you can follow Raju's advice, but as Not2Easy has said, all header content will change for every page. If you edit the main theme your edits will be overwritten on the next theme update. Heed Not2Easy's advice.

Once you have a child theme, if you wish for a specific page type to have a different header, you could edit the page type to point to a different header .php file, which you will need to create yourself. Change all the header references to point to the new header page, and you should be good.

This is a lot of work for a header change.
2:57 pm on Mar 19, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4504
votes: 347


This is a lot of work for a header change.
Yes it is, thanks for adding that TorontoBoy. That is the reason I had asked for more information on what kind of edit was needed. If it was meta data, robots or canonical edits it is easier to use a plugin.
10:43 am on Mar 22, 2019 (gmt 0)

New User from US 

joined:Mar 13, 2019
posts: 3
votes: 0


Thanks TorontoBoy for explaining this so nicely. The header change might be too easy or it might be too complex depending upon the Cymes Poznan requirements.
10:57 pm on June 23, 2019 (gmt 0)

New User from US 

Top Contributors Of The Month

joined:June 21, 2019
posts: 29
votes: 2


I know I am late to the party here but there is another option here...
This works with a child theme or with the main theme, but in my opinion, all WordPress sites should work with child themes. Solves so many issues...

There is a little know feature of WordPress a whole lot of folks don't know... It lets you can create static pages in your theme/child theme directory and use them.
This post is going to assume you have in fact created the child theme.

But the solution....
Ok, create your WP page like you normally would., don't worry about the head section yet. Use a temporary name because you will delete this page later.

Publish the page and visit your page via a browser... now right click the page, select view source. Highlight and copy the source code. you need this source code.

Now in child theme directory create the the following empty page. It must be named like this.....
page_what-ever-name-you-want.php the important part is it must start with "page_".

Open page_what-ever-name-you-want.php in your favorite editor.. then paste in the copied source code.
Make any changes you want to the head section of the page and save it.

You can also delete the WP page you created and copied the source code from at this point. (told you that it would be deleted, you don't need it anymore)

Now go to your WP Dashboard. Create a page with the exact name of the page that starts with page_ but without "page_" in it.

WordPress will look in the child theme folder and use the page you created. Now you can just edit that page as you see fit.
Because you copied the source code the page will use the site theme and look just like any other page on the site.

This will not affect any other page nor any of your WP settings.
Not a whole of work, no plugins to slow you down.. no complications.

Problem solved.
1:13 pm on Sept 18, 2019 (gmt 0)

New User from US 

joined:Sept 18, 2019
posts: 15
votes: 3


Depending on your theme, you might be abloe to go into the specific page in your WP-Admin and do that in the backend, but honestly the easy way (what I always do) if just download a pluging called "Header & Footer Script Injector" - it gives you access to inject script in hte Header, Bodym or Footer, on individual pages or sitewide, on desktop only, mobile only, or both...I use it on all of my sites and it's never failed me
1:59 am on Sept 29, 2019 (gmt 0)

New User from CA 

joined:Sept 25, 2019
posts:21
votes: 2


If you don't want to edit theme files directly, insert headers and footers is a pretty lightweight plugin. There's also a plugin called page add to head or something like that if you need more granular page-level control ie. for schema mark-up