Created
June 20, 2019 05:07
-
-
Save sybrew/39652aab1770f165b04809927b84379f to your computer and use it in GitHub Desktop.
Edit TSF title branding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Don't include the PHP tag in existing files. | |
// Requester: https://wordpress.org/support/topic/filter-to-remove-blogname-from-all-posts-or-other-post-type/ | |
// Where do I place filters? See: https://tsf.fyi/docs/filters#where | |
/** | |
* Adjust The SEO Framework title branding. | |
* | |
* @param bool $use Whether branding is set. | |
* @param array|null $args The query arguments. Accepts 'id' and 'taxonomy'. | |
* Leave null to autodetermine query. | |
* @return bool True when additions are allowed. | |
*/ | |
add_filter( 'the_seo_framework_use_title_branding', function( $use, $args ) { | |
if ( null === $args ) { | |
// We're in the main query... | |
// Unset for all non-page-type queries. | |
if ( is_singular() ) { | |
// Singular query... | |
if ( ! is_page() ) { | |
$use = false; | |
} | |
} else { | |
// Term query... | |
} | |
} else { | |
// We're somewhere on the admin pages or generating structured data. | |
if ( $args['taxonomy'] ) { | |
// Term query... | |
} else { | |
if ( ! $args['id'] ) { | |
// Unknown page. May be home-as-blog page... | |
} else { | |
// Get the post object. | |
$post = get_post( $args['id'] ); | |
// Check if the Post object exists... | |
if ( $post instanceof \WP_Post ) { | |
if ( 'page' !== $post->post_type ) { | |
$use = false; | |
} | |
} | |
} | |
} | |
} | |
return $use; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment