Created
April 10, 2023 16:17
-
-
Save Auke1810/f07745c20a65560baea04c0a89cc1417 to your computer and use it in GitHub Desktop.
This snippet replaces Yoast SEO shortcodes ( '%%title%%', '%%sitename%%','%%sep%%') in title and description attribuut
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 | |
function replace_yoast_seo_title( $attributes, $feed_id, $product_id ) { | |
// replace %%title%% with the product title. | |
$attributes['title'] = str_replace('%%title%%', get_the_title($product_id), $attributes['title']); | |
$attributes['description'] = str_replace('%%title%%', get_the_title($product_id), $attributes['description']); | |
// replace %%sitename%% with the site name | |
$attributes['title'] = str_replace('%%sitename%%', get_bloginfo('name'), $attributes['title']); | |
$attributes['description'] = str_replace('%%sitename%%', get_bloginfo('name'), $attributes['description']); | |
// replace %%sep%% with pipe (Change if you like to have a different separator) | |
$attributes['title'] = str_replace('%%sep%%', '|', $attributes['title']); | |
$attributes['description'] = str_replace('%%sep%%', '|', $attributes['description']); | |
// IMPORTANT! Always return the $attributes | |
return $attributes; | |
} | |
add_filter( 'wppfm_feed_item_value', 'replace_yoast_seo_title', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment