ID, self::META_TITLE_KEY, true );
$desc = get_post_meta( $post->ID, self::META_DESC_KEY, true );
$is_optimized = \AIContentByParallax\Admin\ProductListIntegration::is_product_optimized( $post->ID );
$is_excluded = \AIContentByParallax\Admin\ProductListIntegration::is_product_excluded( $post->ID );
?>
term_id, self::TERM_META_TITLE_KEY, true );
$desc = get_term_meta( $term->term_id, self::TERM_META_DESC_KEY, true );
?>
|
|
|
|
$parts Document title parts.
* @return array
*/
public static function maybe_override_document_title( array $parts ): array {
if ( self::seo_plugin_active() ) {
return $parts;
}
if ( is_singular( 'product' ) ) {
$title = get_post_meta( get_the_ID(), self::META_TITLE_KEY, true );
if ( $title ) {
$parts['title'] = $title;
}
return $parts;
}
if ( is_tax( array( 'product_cat', 'product_tag' ) ) ) {
$term = get_queried_object();
if ( $term instanceof \WP_Term ) {
$title = get_term_meta( $term->term_id, self::TERM_META_TITLE_KEY, true );
if ( $title ) {
$parts['title'] = $title;
}
}
return $parts;
}
return $parts;
}
/**
* Print from Parallax fields when present.
* Skips if an SEO plugin is active (they’ll output their own).
*/
public static function maybe_print_meta_description(): void {
if ( self::seo_plugin_active() ) {
return;
}
$desc = '';
if ( is_singular( 'product' ) ) {
$desc = get_post_meta( get_the_ID(), self::META_DESC_KEY, true );
} elseif ( is_tax( array( 'product_cat', 'product_tag' ) ) ) {
$term = get_queried_object();
if ( $term instanceof \WP_Term ) {
$desc = get_term_meta( $term->term_id, self::TERM_META_DESC_KEY, true );
}
}
$desc = self::sanitize_meta_description( $desc );
if ( $desc ) {
echo '' . "\n";
}
}
/**
* Check if a popular SEO plugin is active.
*/
protected static function seo_plugin_active(): bool {
// Yoast.
if ( defined( 'WPSEO_VERSION' ) ) {
return true;
}
// Rank Math.
if ( defined( 'RANK_MATH_VERSION' ) ) {
return true;
}
// All in One SEO.
if ( defined( 'AIOSEO_VERSION' ) ) {
return true;
}
// SEOPress.
if ( defined( 'SEOPRESS_VERSION' ) ) {
return true;
}
return false;
}
/**
* Sanitize meta description for output/storage.
*
* @param mixed $value Value to sanitize.
* @return string
*/
protected static function sanitize_meta_description( $value ): string {
$value = is_string( $value ) ? $value : '';
$value = wp_strip_all_tags( $value );
$value = preg_replace( '/\s+/', ' ', $value );
$value = trim( $value );
if ( mb_strlen( $value ) > 320 ) {
$value = mb_substr( $value, 0, 320 );
}
return $value;
}
}