Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Maja B.
Maja B.
12,984 Points

the_content()

Hi, anyone knows how to display the_content() but without beeing wrapped into p tags.

I've tried this

<?php echo get_the_content(); ?>

but it does not work.

1 Answer

Andrew Shook
Andrew Shook
31,709 Points

Maja, you almost had it. The correct function is get_content(), this will return the value as just a string.

Maja B.
Maja B.
12,984 Points

Hi, thanks but how?

Both

<?php get_content(); ?>

and

<?php echo get_content(); ?>

give: Fatal error: Call to undefined function get_content() in C:\xampp\htdocs\ajp\wp-content\themes\pho-child\content-commercial-art.php on line 10

Maja B.
Maja B.
12,984 Points

One more think (because I'm not sure that my initial question was clear enough)

The problem with

<?php echo get_the_content(); ?>

is that it writes/echoes:

<p>My content</p>

instead of just bare string - as I would like it to echo:

My content

So can you help me display the content without p tags?

Andrew Shook
Andrew Shook
31,709 Points

Sorry, yes it is get_the_content(), and if you are still getting "p" tags then those are being put in by the wysiwyg editor. In that case try this:

<?php
    echo strip_tags(  get_the_content() );
?>
Maja B.
Maja B.
12,984 Points

Hi, yes, this works! Great!