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
- WP_Query: get 3 random posts from 10 latest
- Show posts without term
- Is there a way to extend WP_query so Custom Post Types can have properties?
- How to Compare Two Meta Fields
- paginate_links ignore my format
- $wp_query initiation?
- Changing Posts Per Page and offset with pre_get_posts
- Show two random posts from custom post type
- Add the “active” class only to the first loop item in a WordPress query [closed]
- pagination doesn’t show up for custom post type
- How to modify query so it grabs only 90 posts in total?
- Get only 1 Most Recently Modified Child Post from Parent
- How to get a category in a list item class
- Trying to check and see if a post has a featured image outside of the main loop
- Pagination doesn’t work in custom page template [duplicate]
- wp_query a single custom post type?
- Should close $wpdb via $wpdb->close()
- Efficient way to update multiple post meta
- Does meta_query need numeric values to be cast to integers?
- How to use Meta Value Compare in WP_Query For Max and Min numbers
- WordPress documentation – WP_Query arguments
- WP_Query with multiple meta fields filter?
- Using apply_filters(‘the_content’, $custom_query->post_content) alters output
- WP_Query Date Query After Minus Hour AND minus minutes
- Shortcode to show thumbnail and link for 3 random posts
- wp query template tags not working
- How to select events within current week using wp_query
- How to display upcoming events by dat with Modern Events Calendar Lite
- Wp_query Add specific pending posts
- How to Filter Posts by Custom Fields?
- Display posts from only one post form in custom query and exclude in main query
- Get pagination working for custom loops within page templates
- pagination with ‘no_found_rows’ => true,
- How to get all product attributes for filters in WooCommerce?
- Fetch Record based on meta key dates
- How can I display list of all posts from a specific author, with publish dates in the future, on an author archive page (author.php)?
- Custom posts visible in admin, but truncate in public
- Query to get siblings and parent page
- Query posts from category A, and from either category B or C
- Why does get_posts only show results for Admins or logged-out users?
- Query posts with “non set” meta value
- Add filter post_where and passing post_type argument
- WP_Query infinite Loop
- Limiting number of related posts
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- WP Query – order posts by meta field first and then order the rest
- Reusing content from front page on sub page
- Get Child Page IDs by Parent ID
- how would i change post->ID to work correctly when querying pages?
- Pagination works in custom query loop but it doesn’t work in shortcode
- How to apply a function to a metadata value before launch a WP Query?
- Pagination for custom loop on custom page template is not displaying anything
- Display posts by tag
- Writing less unnecessary code with WordPress
- query single random post works localhost, not on live site
- How to sort by most watched in X days/months
- Replace wp_query with wp_user_query
- How can I use arrays and a foreach to generate many lists with WP_Query?
- WP_Query breaking the loop in a nested loop
- WordPress Query for CPT that only shows posts within radius of current user’s geolocation
- How to get user avatar via WPDB
- One of two similar WP Query is very slow
- WP_Query – multiple orderby with a rand field, doesn’t work
- What does $temp do?
- Woocomerce – Order products by float attribute in archive pages
- Complex Meta Query
- Is instantiating WP_Query not possible within an admin Ajax call?
- wp_query sorting – one specific meta_key value at last and then sort by create date
- WordPress conflict with multiple load more posts functions on click
- why default wordpress loop not working outside index.php
- Category Archive not working for pages
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Order posts by more than one variable (meta_key and publish date AND time)
- How can I get all the posts that are related with a specific taxonomy term?
- Create custom order sortby based on array of id
- How to combine nested tax_query logic with other nested query logic?
- complex query question
- Showing Children of page by name
- WP_Query for liked posts is showing all posts if none are liked
- Get closest event where meta_key field is an array
- Custom shortcode not displaying categories and correct date
- Set right order for query that returns posts based on two custom fields
- Meta_query weird behaviour
- Manipulating a query
- Can’t get pagination to work with this WP_Query loop
- Modify query after meta value
- How can I filter a query by post id?
- WP query with multiple custom meta not respecting orderby
- AJAX search function resets wp_query vars
- I need to get all categories from a WP_Query