0

I have this code:

add_filter( 'the_title', function() {
    return "";
});

Or, respecting the hook's arguments:

function remove_title( $title, $id ) {
    $title = '';
    return $title;
}

add_filter( 'the_title', 'remove_title', 999, 2);

Which is being placed in a custom made page, my template (used by that page) being:

get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main">
        <header class="entry-header">
            <?php the_title('<h1 class="entry-title">', '</h1>'); ?>
        </header><!-- .entry-header -->
        <?php
        while ( have_posts() ) :
            the_post();
            ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <?php
                    the_content();
                ?>
            </article><!-- #post-<?php the_ID(); ?> -->
        <?php
        endwhile; ?>
    </main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
  • 1
    Where do you place your filter code? Why can't you simply edit this template? Do you want to hide titles on all pages and posts? Shouldn't there be some conditions in your filter? – Krzysiek Dróżdż May 23 '18 at 13:07
  • you can remove '<?php the_title('<h1 class="entry-title">', '</h1>'); ?>' from your code, and if you want to limit it to few pages then you can add a condition or add a custom field for this template so whenever this is selected, you'll get the option to show or hide title at admin area and you can set condition accordingly in the template. – Akshat May 23 '18 at 15:04
0

You can try this

function wpb_hidetitle_class($classes) {

    if ( is_single() || is_page() ) : 
        $classes[] = 'hidetitle';
        return $classes;
    endif;

    return $classes;

}

add_filter('post_class', 'wpb_hidetitle_class');

CSS code :

.hidetitle .entry-title { 
    display : none;
}

Source http://www.wpbeginner.com/plugins/how-to-hide-post-and-page-titles-in-wordpress-single-pages/

  • 1
    Ehhh, wpbeginner is really annoying with these dummy tips. This is not a solution - it only makes title invisible - it is still in your HTML, it is still read by browsers and so on... – Krzysiek Dróżdż May 23 '18 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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