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 trialRalf Koller
4,506 PointsHow to apply classes to wysiwyg field content?
i've one slight problem. I've built a news custom post type with custom post type ui and advanced custom fields.in the backend i normally use text area fields since they are unstyled without any enclosing tags so they are easier to place. but in the case of the wysiwyg field that way isn't viable since per default content is enclosed in paragraph tags.
<div>
<?php the_field( 'news_post' ); ?>
</div>
leads to
<div>
<p> content </p>
</div>
but is there a way to apply a class to the p tag like
<div>
<p class="mydesiredclass"> content </p>
</div>
best regards ralf
4 Answers
István Turupoli
11,950 PointsIf the class is only for styling, you could just add the class to the parent div, and use a child selector ( div > p ) in the css.
Crisoforo Gaspar Hernández
18,302 PointsYou could use the php function: strip_tags
as follows:
$text = "<p>Test paragraph.</p><a href='#fragment'>Other text</a>";
echo strip_tags($text);
echo "\n";
// Allows <p> and <a>
echo strip_tags($text, '<p><a>');
Outputs
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
Matt Campbell
9,767 PointsWrap <?php the_content(); ?> in a div and give the div the class. Then you can .class element and you're golden.
Ralf Koller
4,506 Pointsthanks! to style based on the wrapping parent div is a good idea. easy to apply. i think i will go for that. thanks again!