0

I have created a custom page template and want to hide page title from the page.

How do I do this? I know I can just leave page title blank or do it in CSS and that works but isn't that bad for SEO etc? How do I write the conditional statement and where do I put it?

Here is my template:

<?php
/*
Template Name: No Title Page
*/
?>

<?php get_header(); ?>
<div class="wrapper">
    <?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', 'page' ); ?>
    <?php endwhile; // end of the loop. ?>
</div>

<?php get_footer(); ?>
1
  • 2
    It's impossible to say since this get_template_part( 'content', 'page' ); is loading another template file that you have not showed us.
    – Wyck
    Commented Nov 1, 2014 at 2:06

4 Answers 4

4

It's simple:

Don't forget to move add_filter to functions.php file :)

<?php
/*
Template Name: No Title Page
*/ 
add_filter( 'the_title', function ($title) { return "";});
?>

<?php get_header(); ?>
<div class="wrapper">
    <?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', 'page' ); ?>
    <?php endwhile; // end of the loop. ?>
</div>

<?php get_footer(); ?>
14
  • 1
    I understand the logic behind what you've done but perhaps you could explain it?
    – s_ha_dum
    Commented Nov 1, 2014 at 4:31
  • Thanks Vladimir! That worked like a charm! I did however have to move that line down under the get header otherwise it was hiding my menu. Otherwise PERFECT! Thanks again! Commented Nov 1, 2014 at 9:49
  • @oOPurple_HazeOo welcome :) Commented Nov 1, 2014 at 9:56
  • create_function Really? Commented Nov 1, 2014 at 10:51
  • @PieterGoosen Why no ? :) Commented Nov 1, 2014 at 11:48
0

Your NO TITLE page is calling function

get_template_part( 'content', 'page' );

Which means its calling page 'content-page.php'

I won't recommended to edit this page directly as it might be used at other places in theme.

Solution:

Copy content-page.php and name it content-notitle.php

The remove title from new copied page.

Now you can call this function in your 'No Title Page' custom template like this

get_template_part( 'content', 'notitle' ); 

This should work for you.

0
-1

Inside your get_template_part() you can find the_title() function that prints page title.

Simple comment it out or delete it, but never, NEVER use display:none with CSS.

-3

Page title can be used in the following code:

<?php the_title( '<h1 class="title-header">', '</h1>' ); ?>

If you'd like to hide it use you can hide it with CSS or comment it out.

CSS:

h1.title-header{
   display: none;
}

Hiding the element with CSS search engines read the page title even though it doesn't appear on the page.

2
  • 1
    Please format your code properly. Commented Nov 1, 2014 at 2:27
  • Please do not roll back my changes. I have properly formatted your code already. Just a tip, if you add code to a post, highlight it in the editor and click on the {} sign above the editor. This will add your code in a code block Commented Nov 2, 2014 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.