Skip to content

Instantly share code, notes, and snippets.

@sybrew
Last active November 22, 2024 06:29
Show Gist options
  • Save sybrew/014931e5589293cc0f3ea9b57f6d6f8a to your computer and use it in GitHub Desktop.
Save sybrew/014931e5589293cc0f3ea9b57f6d6f8a to your computer and use it in GitHub Desktop.
Adjust WooCommerce title for The SEO Framework with "Hot " at the start.
<?php
// Do not include the PHP opening tag if PHP is already opened.
add_filter(
'the_seo_framework_title_from_generation',
function ( $title, $args ) {
$is_product = false;
$is_product_category = false;
if ( isset( $args ) ) {
switch ( \The_SEO_Framework\get_query_type_from_args( $args ) ) {
case 'term':
$is_product_category = 'product_cat' === $args['tax'];
break;
case 'single':
$is_product = tsf()->query()->is_product( $args['id'] );
}
} else {
if ( tsf()->query()->is_product() ) {
$is_product = true;
} elseif ( \function_exists( 'is_product_category' ) && is_product_category() ) {
$is_product_category = true;
}
}
if ( $is_product || $is_product_category ) {
$title = "Hot $title";
}
return $title;
},
10,
2,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment