Alter only the page title, not the post titles within

I believe that the page title you are talking about is the title from the page from the main query. the_title() filter (and the_content() filter for that matter) targets all the respective template tags regardless of query.

To avoid this, target only the main query and the specific page.

You can try the following inside your filter

if ( in_the_loop() && is_page( 'specific page' ) ) {

    // Do what you need to do

}

EDIT

I just thought of this, haven’t tested it, but you can check your title inside the filter against a known static title and then do something according to that

Example:

if ( $title == 'My known title' ) {

    // Do something with the title

}

Leave a Comment