Skip to content

Instantly share code, notes, and snippets.

@sybrew
Created April 16, 2024 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sybrew/971e49138e0841fa18a413a6bd24e561 to your computer and use it in GitHub Desktop.
Save sybrew/971e49138e0841fa18a413a6bd24e561 to your computer and use it in GitHub Desktop.
Sets TSF taxonomy title parts for taxonomy 'module'.
<?php
// Do not include the PHP opening tag if PHP is already open.
// For request: https://wordpress.org/support/topic/way-to-automatically-create-custom-meta-titles/
add_filter(
'the_seo_framework_generated_archive_title_items',
/**
* @param String[title,prefix,title_without_prefix] $items The generated archive title items.
* @param \WP_Term|\WP_User|\WP_Post_Type|null $object The archive object.
* Is null when query is autodetermined.
* @param string $title_without_prefix Archive title without prefix.
* @param string $prefix Archive title prefix.
* @return String[title,prefix,title_without_prefix] Modified $items with " article" appended for taxonomy 'module'.
*/
function ( $items, $object, $title, $title_without_prefix, $prefix ) {
if ( isset( $object ) ) {
// Admin area
$is_module = 'module' === ( $object->taxonomy ?? '' );
} else {
// Front-end
$is_module = is_tax( 'module' );
}
if ( $is_module ) {
// $items[0] = $title.
$items[0] = "$title article";
// $items[2] = $title_without_prefix.
$items[2] = "$title_without_prefix article";
}
return $items;
},
10,
5,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment