-2

I'm having a problem with displaying the_content() of my custom post type. Apparently when I use the code in my single-project.php page, it outputs with a div showing the post title. Why does this happen and how do I get rid of it?

<?php if ( get_the_content() ) : ?>
<div class=" content post__text">
<?php the_content(); ?>
</div>
<?php
endif;?>

output of above code:

<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis maximus urna. Vestibulum vel nisl fermentum, ultrices felis quis, euismod massa. Sed tristique enim ut mauris cursus, non placerat est luctus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>

<div> Test Project Title</div>

jps
  • 20,041
  • 15
  • 75
  • 79

1 Answers1

0

By default the_content() will display tags. If you want to strip tags from the_content() you can use a function like so:

wp_strip_all_tags():

echo wp_strip_all_tags(the_content())

if you wanted to strip certain HTML you could use something like:

function so_62136989( $content ) {
    return strip_tags( $content, '<p><div>' );
}
add_filter( 'the_content', 'so_62136989' );
DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127
  • Hi thanks for your reply. I believe somehow the post title is being added as a filter to the the_content hook. I tried your method so the content gets stripped the but the title is still shown. I am not sure if this is a core WP thing? because i do have that code in the post-single-project.php page. So maybe i am missing something and it's activating a certain if statement to show that. – Malak Reyadh Jun 12 '20 at 18:47