So I have plugin that pulls remote data (real estate listings) into a wordpress site. I have been asked by a client to allow the page title for each listing to be set based upon that information and formatted the way they want. I can use the_title filter to change the content of the title easily enough, but I am running into a problem with the $before and $after elements impacting the formatting. For example, twentyfourteen uses this to output a page title:
the_title( '<header class="entry-header"><h1 class="entry-title">', '</h1></header><!-- .entry-header -->' );
So if I run the_title filter and do something like this (greatly simplified):
add_filter( 'the_title', 'fls_mls_listing_title_filter', 30, 2 );
function fls_mls_listing_title_filter( $title, $id ) {
if ( in_the_loop() ) {
$new_title = 'Something: <h1>Main Title</h1><p>Subtitle</p>'
return $new_title;
}
return $title;
}
I end up with this:
<header class="entry-header">
<h1 class="entry-title">Something</h1>
<h1>Main Title</h1>
<p>Subtitle</p>
</header><!-- .entry-header -->
But I would like to end up with this:
Something
<h1>Main Title</h1>
<p>Subtitle</p>
Obviously this is not a very logical example, but I wrote it just to keep it simple. I need to do this from within the plugin and without creating a custom page template so it will work with any theme if possible. Any insights would be greatly appreciated.