the_content filter & custom posts

I have the following situation:

I’ve got a custom post ‘my_custom_post’ that has no ‘rewrite’, so it does not have it’s own pages. It is just used to generate some text somewhere on some page.

While reading the custom posts I apply the the_content filter like this:
$my_content = apply_filters( 'the_content', get_the_content() );

I need to apply the the_content filter.

So far so good.

For my posts and pages I add some text before all content like this:

add_filter('the_content', 'myfunc_add_before_page_content', -1 );
function myfunc_add_before_page_content( $content ){
	if( ( is_single() || is_page() ) && in_the_loop() && is_main_query() ) {
		return( "some text" . $content );
	}
	else
	{
		return( $content );
	}
}

The problem is that “some text” is added to the above custom post ‘my_custom_post’ as well. If it was a custom post with a ‘rewrite’ and having its own page, I could add
&& !is_singular('my_custom_post')
to myfunc_add_before_page_content( ).

Is there any way of knowing inside myfunc_add_before_page_content( ) what kind of post the content being filtered belongs to? Or what the ID of that post is? That way I could ignore my custom posts in the filter. Or is there a simpler way that I just don’t see?

I am sort of stuck with this…



Source link