I'm using the Enigma theme in my webpage and I want to hide the title of some posts without using any plugins. Every tutorial I find on the internet teaches me how to do it in a incompatible way for my theme. The TAGs of the HTML and the CSS code aren't matching with the structure of mine. So I need some help to do it.
2 Answers
If there is only 1 post showing up in your page, you could use the the_title()
filter to hide the title.
The simplest way would be this:
function hide_my_title( $title, $id = null ) {
if ( is_single( 2 ) ) {
return '';
}
return $title;
}
add_filter( 'the_title', 'hide_my_title', 10, 2 );
This will hide the title when you are viewing the post with an ID of 2. Notice, this might also hide the title for another posts if some elements such as related posts are being used on this page.
-
That would be a elegant solution but in our case isn't totally applicable. Because hiding the text of the title would still create the tags h1 and a in the page.– N. GomesCommented Dec 21, 2017 at 10:57
We found a solution for our problem making a little change in the code of the file post-content.php, line 32. Original:
<h2><?php if(!is_single()) {?><a href="<?php the_permalink(); ?>"><?php } ?><?php the_title(); ?></a></h2>
Updated:
<?php if(!is_single()) {?><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><?php } ?>
i appreciate all the help you've given me.