I'm writing a plugin that adds a banner to the top of all blog posts. I'm using the_content
filter and just pre-pending some html to it. When doing this, the html isn't shown in the excerpt, but I want the banner to be there. What do I need to do? I don't want to allow any additional html tags that users can put in the excerpt.
Edit:
I'm now using a combination of the_content
and the excerpt
filters to display the banner. I don't want to just add the banner to the content, it displays on the content page, but not the post list page. Using just the_excerpt
will only display on the post list page (depending on the theme) and not the individual post page. I've been using the is_single
function to help distinguish between the post list page and the page for a single post. Here is what my code looks like so far.
function display_banner( $content ) {
return '<div class="banner">Banner</div>' . $content;
}
function display_content_banner() {
if ( is_single() ) {
return display_banner( $content );
} else {
return $content; //on the post list page, the_excerpt is in charge of displaying the banner.
}
}
add_filter('the_excerpt', 'display_banner');
add_filter('the_content', 'display_content_banner');
The problem I'm getting is that some themes don't display the excerpt on the post list page, they display to full post text, so my banner is not getting placed when this occurs.
the_excerpt