remove page title from some pages
-
Hello
I am using twenty ten theme and I would like to hide the page title from a couple of pages i.e. home etc.Could anyone advise the best way to do this?
Kindest regards
-
You can use conditional tags and edit your theme files, but it requires some coding knowledge.
Example:
<?php if (!is_page(array('blah','blah2','blah3'))); ?> <h2><?php the_title(); ?></h2> <?php endif; ?>
This says: For pages that do not have the slug blah, blah2, and blah3, display the title.
Reference: https://codex.www.ads-software.com/Function_Reference/is_page
Another way to do it is to hide them via CSS. You’d look in the page source in a browser and find the unique body class for the pages where you want to hide the post title.
Then in your CSS, you put the corresponding page classes and make the titles display: none (hidden). For example:
.page-id-117 .title-class, .page-id-248 .title-class, .page-id-874 .title-class { display: none; }
This hides the titles for humans, but search engines would still see them. You’d have to verify the actual title class in TwentyTen.
Warning: Do not edit the TwentyTen theme directly or all your changes will be overwritten the next time you update the theme. Use a child theme instead. There are many tutorials out there on creating child themes, such as this one.
p.s. if you use the PHP conditionals method, there are different conditionals for the homepage and the front page as they are “special”:
is_home()
andis_front_page()
See the complete WordPress conditionals reference here for more info:
Sorry which file would I change the conditional tags?
Is it the functions file? I have created a child theme.
Sorry I am completely new to WP. I only want to remove the page title on 3 pages. Thanks
It would be whatever file where your title code is displayed – example, page.php for pages, index.php for blog homepage, etc. More about the WordPress template hierarchy:
p.s. if you’re really new to WordPress and not yet comfortable with editing theme files, the second (CSS) method I proposed above will likely be much easier for you.
Thank you Zoonini. I tried your code but it gave me an error that the endif; was misplaced or something. I changed your example a little and it worked perfectly using this code in the page.php file.
<?php if (!is_page(array('blah1','blah2','blah3'))) { ?> <h1><?php the_title(); ?></h1> <?php } ?>
Glad you figured it out!
Sorry about that, it should have been a colon instead of a semi-colon in the first line – but the curly brackets are fine too:
<?php if (!is_page(array('blah','blah2','blah3'))): ?> <h2><?php the_title(); ?></h2> <?php endif; ?>
Hello
I have tried the css, but it doesnt work and I am not advanced enough to change the files yet.To hide all page titles this does work in the CSS for twenty ten:
.page .entry-title{display:none;}
Is there anyway of modifying this for the 3 pages i want to hide the title?
ThanksCan you provide a link to your site so I can check the classes?
As I mentioned above, you need to check the body class of each page where you want to hide the title. So if the classes are page-id-248 and page-id-398, for example, do:
.page-id-248 .entry-title, .page-id-398 .entry-title { display:none; }
… and so on. Just add more classes separated by commas, following the syntax above for as many pages whose titles you want to hide.
hello
many thanks for getting back to me, could you check the classes for the pages I would like to hide the page title? (When I checked the classes they come up as post.php?post=84 – is that correct?)Many thanks
Anna
https://www.kidsmoderndesign.co.uk/shop-by-designer/
https://www.kidsmoderndesign.co.uk/
https://www.kidsmoderndesign.co.uk/shop-by-brand/You need to open each page in a web browser, and View Source – the location of View Source in the menu is different depending on the browser.
When looking at the source of each page, find the body tag and locate the unique class in each. Your examples above are:
<body class=”page page-id-77 page-parent page-template page-template-onecolumn-page-php custom-background”>
<body class=”home page page-id-1332 page-template page-template-onecolumn-page-php custom-background”>
<body class=”page page-id-84 page-parent page-template page-template-onecolumn-page-php custom-background”>
I’ve put each unique class in bold.
That translates to:
.page-id-77 .entry-title, .page-id-1332 .entry-title, .page-id-84 .entry-title { display:none; }
Does that make sense?
yes it does, sorry i was getting confused with the page id appearing as a post not page! Thank you so much for your patience! It works!
Good stuff, I’m glad you got it working!
I am having the same issue with my site, but I don’t see any style applied to the body of the page. Would someone be willing to take a look at my page and help me figure out how to hide the “title” on my homepage using CSS?
This is my first time posting do I include a link to the website?
- The topic ‘remove page title from some pages’ is closed to new replies.