You could check if the current post ID is the same as the ‘queried object’ ID, which is whichever post the current URL represents, and is separate from the current post within the loop. If both those IDs are the same then you can assume that the current content being filtered is for the content of the main post, and not a nested query for a different post.
function wpse_308358_content_filter( $content ) {
if ( is_single() && get_queried_object_id() === get_the_ID() ) {
$content .= 'Appended content.';
}
return $content;
}
add_filter( 'the_content', 'wpse_308358_content_filter' );
is_single()
adds protection against the possibility that you’re displaying the full content on category archives and you have a category that happens to have the same ID as a post.
Related Posts:
- how can I get seperate the HTML in the_content(); output?
- has_excerpt() not working inside wp_query
- How to split a post and intercalate elements from a loop
- Display specific page (that is child) content on parent page
- custom page with post content using read more
- Why is get_the_excerpt returning full content
- Why does apply_filters behave different inside and outside a loop?
- Links in the_content not linked
- Insert wp_query after the_content with plugin (filter the_content won’t work)
- Can’t get the_content to show
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- WP_Query by just the id?
- Meta_query compare operator explanation
- WP_Query with “post_title LIKE ‘something%'”?
- wp query to get child pages of current page
- How to get an array of post data from wp_query result?
- How to get post id of static front page?
- meta_query with meta values as serialize arrays
- How to only display posts whose meta_value field is not empty?
- Get post ids from WP_Query?
- Pagination when using wp_query?
- Exclude post ID from wp_query
- How to print the excuted sql right after its execution
- How to extend WP_Query to include custom table in query?
- How to store and receive variables in WP sessions?
- Should I use Pre Get Posts or WP_Query
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Nested meta_query with multiple relation keys
- Is it necessary to use wp_reset_query() in a WP_Query call?
- Can I force WP_Query to return no results?
- Can wp_query return posts meta in a single request?
- Using pre_get_posts with WP_Query
- Find out total number of pages in global query on archive page?
- WP_Query + random
- Resetting post data to previous loop in nested loops
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Broken? WP_Query and “attachment” as a post type
- Some doubts about how the main query and the custom query works in this custom theme?
- Order by multiple meta key and meta value [closed]
- Post_count only shows the number of results per page
- Page template query with WP_Query
- meta_query ‘compare’ => ‘IN’ not working
- Query posts only with featured image
- Wp get all the sub pages of the parent using wp query
- What is appropriate flow for custom data from URL in WP_Query?
- How to display page content in a page template?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How to merge two queries together
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- why ignore_sticky_posts in sticky post query
- Wp_redirect and sending variables
- Multiple relationship for multiple tax_query in WP_Query
- How do I get posts that have a thumbnail in WP_Query?
- Multiple WP_Query loops with Pagination
- How do I query for posts by partial meta key?
- Pagination with custom SQL query
- Return only Count from a wp_query request?
- Using a custom WP_Query with get_template_part loop
- Use REGEXP in WP_Query meta_query key
- Why is the loop not empty on some 404s?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP Query Args – Title or Meta Value
- How to query for most viewed posts and show top 5
- WP_Query orderby date not working
- WordPress Pagination Not Working – Always Showing First Pages Content
- Best way to detect if you are in a SINGLE POST page
- Meta query with string starting like pattern
- WP Query where title begins with a specific letter
- WordPress tax_query “and” operator not functioning as desired
- compare meta_query in get_posts arguments
- Custom taxonomy query broken after upgrade to 4.4
- WordPress retrieving meta data for all custom post types in list view
- How to query posts based on lat-lng coordinate as post meta?
- How to use the_posts_navigation for wp_query and get_posts?
- WP_Query vs get_posts
- Is it possible to completely stop WP_Query retrieving posts?
- how to show posts that are missing a meta_value
- What is “main query”? [duplicate]
- Use the page slug in a WP_Query?
- Order by optional meta key?
- Set Alias for meta_query arguments in get_posts()
- get_queried_object() returns null on post date archive
- How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?
- Sorting: custom query with orderby meta_value_num THEN by title
- Loop within a loop?
- Order by DESC, ASC in custom WP_Query
- Exclude or Include category ids in WP_Query
- WP_Query: get 3 random posts from 10 latest
- WP_Query and next_posts_link
- get_query_var function not working at all
- WP_Query order by multiple meta keys & fields
- Show posts without term
- get_query_var( ‘paged’ ) not working outside of homepage
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- meta_query: using BETWEEN with floats and/or casting to DECIMAL
- How to remove_query_arg() for paginate_links()