Yoast search engine optimization snippets to customise your website • Yoast


Yoast search engine optimization routinely handles all kinds of issues on your website. Options like meta tags, schema, sitemaps, and content material evaluation aid you rank increased in natural search outcomes. Nonetheless, you will have a customized or particular use case that requires adjusting how our plugin works on your website. Yoast search engine optimization contains filters that enable you or your developer to customise lots of the options in our plugin. Let’s dive into among the widespread Yoast search engine optimization snippets and real-world examples of instances you might want to make use of these snippets.

Modify breadcrumb output

A well-liked front-end output is the breadcrumb path that themes can use on the prime of content material objects, like posts and pages. Yoast search engine optimization contains widespread path choices, however customization can profit some content material sorts. The code snippet beneath provides a customized hyperlink between the Residence and Put up Title that seems by default. Thus, Residence » Whats up world! turns into Residence » Weblog » Whats up world!. You will discover extra examples right here.

add_filter( ‘wpseo_breadcrumb_links’, ‘yoast_seo_breadcrumb_append_link’ );

operate yoast_seo_breadcrumb_append_link( $hyperlinks ) {
international $put up;
$post_id_to_change = 1;
$url_to_add = site_url( ‘/weblog/’ );
$anchor_text_for_url_to_add = ‘Weblog’;

if ( is_single ( $post_id_to_change ) ) {
$breadcrumb[] = array(
‘url’ => $url_to_add,
‘textual content’ => $anchor_text_for_url_to_add,

array_splice( $hyperlinks, 1, -2, $breadcrumb );

return $hyperlinks;

Replace picture URLs for CDN

Some websites use a CDN to assist photographs load quicker by serving them from many servers worldwide. A CDN gives you with a special area for photographs.

To make sure social media platforms use the CDN permalink for social media photographs, it is advisable to add this small Yoast search engine optimization code snippet after changing current_example.com and new_example.com along with your WordPress and CDN domains, respectively. Thus, https://current_example.com/wp-content/uploads/2024/02/picture.png turns into https://new_example.com/wp-content/uploads/2024/02/picture.png. You will discover extra examples right here.

add_filter( ‘wpseo_opengraph_image’, ‘change_opengraph_image_url’ );

operate change_opengraph_image_url( $url ) {
return str_replace(‘current_example.com’, ‘new_example.com’, $url);

To replace the sitemap picture URLs, the next code will change https://www.instance.com with https://cdn.instance.com.

add_filter( ‘wpseo_xml_sitemap_img_src’, ‘wpseo_cdn_filter’ );

operate wpseo_cdn_filter( $uri ) {
return str_replace( ‘https://www.instance.com’, ‘https://cdn.instance.com’, $uri );

Add customized template variables

Yoast search engine optimization contains a wide range of variables to construct dynamic titles and descriptions. Nonetheless, these might not present the precise info you need to embody within the title or description. The next snippet creates a customized variable %%myname%% that outputs a sentence My title is Moses within the front-end output.

add_action(‘wpseo_register_extra_replacements’, ‘register_custom_yoast_variables’);

operate get_myname() {
return ‘My title is Moses’;

operate register_custom_yoast_variables() {
wpseo_register_var_replacement( ‘%%myname%%’, ‘get_myname’, ‘superior’, ‘some assist textual content’ );

Alter the variety of sitemap entries

Yoast search engine optimization sitemaps embody as much as 1000 entries the person sitemaps. The restrict is appropriate for many server configurations, however your server might have kind of sources out there. The filter helps you be accountable for your server sources.

add_filter( ‘wpseo_sitemap_entries_per_page’, ‘max_entries_per_sitemap’ );

operate max_entries_per_sitemap() {
return 100;


Whereas Yoast search engine optimization does a whole lot of the heavy lifting, generally you might have to tweak one thing. Maybe a special breadcrumb output would match higher along with your model. Fortunately, Yoast search engine optimization provides a variety of filters so that you could fine-tune our plugin. On this put up, we’ve checked out just a few, however there are numerous extra filters in our developer portal you could attempt! Good luck!

Angelia Embler

Angelia is a senior assist engineer at Yoast. As a part of the Help staff, she enjoys breaking advanced points into straightforward to grasp phrases.

Avatar of Angelia Embler


Supply hyperlink

Marvel Legends Sequence Iron Man Digital Helmet, Multicolor

Understanding corrosion to allow next-generation metals