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>
</ul>
</div>';
return $content . $extra;
} else {
return $content;
}
}
add_filter('the_content', 'eri_course_archive_content_filter');
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0