Single filter call
Just give this plugin a try. It illustrates the whole technique.
<?php
/** Plugin Name: (#69351) Example single filter call on <code>'the_content'</code> */
function wpse69351_single_call( $content )
{
// Only for single view request (post, page, etc.)
if ( ! is_singular() )
return $content;
// This removes the filter during its first call
remove_filter( current_filter(), __FUNCTION__ );
$custom = '<h1>I am only here once!</h1>';
return $content.$custom;
}
add_filter( 'the_content', 'wpse69351_single_call' );
If you’re not targeting the content itself, but more the LOOP, then try this example plugin.
<?php
/** Plugin Name: (#69351) Example single filter call on <code>'loop_start'</code> & <code>'loop_end'</code> */
function wpse69351_single_call( $wp_query )
{
// Abort in some case
if ( 'post' !== get_query_var( 'post_type' ) )
return;
// This removes the filter during its first call
remove_filter( current_filter(), __FUNCTION__ );
return print '<h1>I am only here once!</h1>';
}
// Attach something to the START of the loop
add_action( 'loop_end', 'wpse69351_single_call' );
// Attach something to the END of the loop
add_action( 'loop_start', 'wpse69351_single_call' );
Incomplete Themes
I also considered attaching my filter to the footer instead of the content, but I’ve run across themes that don’t have a footer.
Never ever even dare to think about caring for incomplete themes. We got Theme development guidelines for a reason and a call to wp_footer();
is a must have for every theme. Else, just think “it’s crap!” by yourself and move on.