How do I add custom HTML to the content of an archive page’s posts?


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');
Mr Gandy 2 years 2020-12-17T11:10:38-05:00 0 Answers 7 views 0

Leave an answer