I have a plugin with a custom post type for courses. I want to customize the content inside of the archive page's posts and style it. I realize that the archive page is using the_content() to retrieve the posts' content, and I'm able to use the corresponding filter to customize it; however, it's stripping the HTML and not allowing me to style it. How do I get past this?

function eri_course_archive_content_filter($content) {
    if (is_post_type_archive( 'eri-courses' )) {
        $content = (strlen($content) <= 140)? $content : wp_html_excerpt($content, 140);
        $extra = '<div class="x-text">
                <ul class="x-ul-icons" style="padding-left: 1%;">
                    <li class="x-li-icon" style="padding-bottom: 1%;"><i class="x-icon-o-dollar-sign" aria-hidden="true" style="color: #47c3d3;" data-x-icon-o=""></i><strong>Cost:</strong>  '.get_post_meta( get_the_ID() , '_post_cost', true ).'</li>
                    <li class="x-li-icon" style="padding-bottom: 1%;"><i class="x-icon-o-clock" aria-hidden="true" style="color: #47c3d3;" data-x-icon-o=""></i><strong>Time:</strong> '.get_post_meta( get_the_ID() , '_post_time', true ).'</li>
        return $content . $extra;
    } else {
        return $content;
add_filter('the_content', 'eri_course_archive_content_filter');

1 Answer 1


Try changing the priority, there could be other filters being applied afterwards, i.e:

add_filter( 'the_content', 'eri_course_archive_content_filter', 999 );

If that doesn't work, check that the_content() is actually being called in your archive template, because for example: echo get_the_content(); will not apply any filters set on the_content

  • Thanks @tdk. I tried it and it didn't work, so maybe you're right about get_the_content(). Being that I'm doing this for a plugin, I'm not using a custom archive page. I am trying to access and manipulate the default content that any theme would use. Such as how post templates all call for the_content() no matter what the theme is. Is there a work-around for get_the_content()?
    – Michael
    Dec 17, 2020 at 19:46
  • Or is there a hook that allows you to add stuff after get_the_content() inside the archive page posts?
    – Michael
    Dec 17, 2020 at 20:10
  • get_the_content() currently only has one filter: developer.wordpress.org/reference/functions/get_the_content given that this is an archive page and it might only show excerpts, maybe you're looking for: add_filter( 'the_excerpt', 'eri_course_archive_content_filter' );
    – tdj
    Dec 17, 2020 at 20:39

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.