Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Auke1810/f07745c20a65560baea04c0a89cc1417 to your computer and use it in GitHub Desktop.
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
<?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