0

I want to add different classes to some excerpts.when wrap the excerpt with

it doesn't work.how can I add my class to excerpt?

<?php
<p class="myclass"><?php the_excerpt(); ?></p>

output:

<p class="myclass"></p><p>excerpt text</p>

1 Answer 1

1

the_excerpt() function bascially echo(es) the get_the_excerpt() function output, which in turns wraps the $post->post_excerpt value in html <p> tags.

So you can either strip the html markup,

<p class="myclass"><?= wp_strip_all_tags( get_the_excerpt(), true ) ?></p>

or, if you have access to the $post object simply,

<p class="myclass"><?= $post->post_excerpt ?></p>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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