Categories
Posts

Disabling the Yoast sitemap’s stylesheet

If, for whatever reason, you’d like to disable the stylesheet that comes with Yoast’s sitemap, add the following piece of code to your theme’s functions.php:

add_filter('wpseo_stylesheet_url', 'disable_wpseo_stylesheet_url');

function disable_wpseo_stylesheet_url($stylesheet) {
    return '';
}

In case you are wondering, this is made possible by how Yoast implements the get_output(…) function in class-sitemaps-renderer.php:

/**
 * Produce final XML output with debug information.
 *
 * @param string  $sitemap   Sitemap XML.
 * @param boolean $transient Transient cache flag.
 *
 * @return string
 */
public function get_output( $sitemap, $transient ) {

    $output = '<?xml version="1.0" encoding="' . esc_attr( $this->output_charset ) . '"?>';

    if ( $this->stylesheet ) {
        /**
            * Filter the stylesheet URL for the XML sitemap.
            *
            * @param string $stylesheet Stylesheet URL.
            */
        $output .= apply_filters( 'wpseo_stylesheet_url', $this->stylesheet ) . "\n";
    }

    $output .= $sitemap;
    $output .= "\n<!-- XML Sitemap generated by Yoast SEO -->";

    return $output;
}

As you can see, the function calls the wpseo_stylesheet_url filter in line 19. This enables developers to post-process the stylesheet URL by defining a corresponding filter function (e.g. disable_wpseo_stylesheet_url).