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');
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');
Share
Improve this question
asked Dec 17, 2020 at 17:07
MichaelMichael
2811 silver badge14 bronze badges
1 Answer
Reset to default 1Try 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