-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
35 lines (32 loc) · 1.2 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Plugin Name: Yoast SEO sitemap fix
* Plugin URI: https://github.com/xemlock/wordpress-seo-sitemap-fix
* Description: Fixes Yoast SEO sitemap error: <a href="https://yoast.com/help/xml-sitemap-error/">XML declaration allowed only at the start of the document</a>
* Version: 0.1.0
* Author: xemlock
* Author URI: https://github.com/xemlock
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
defined('WPINC') || die;
(function () {
if (preg_match('#^/sitemap_index\.xml($|\?)#', $_SERVER['REQUEST_URI'])) {
ob_start();
add_action('init', function () {
add_filter('wpseo_sitemap_index', function ($xml) {
while (ob_end_clean());
return $xml;
});
});
} elseif (preg_match('#^/([-_a-z0-9]+)-sitemap\.xml($|\?)#', $_SERVER['REQUEST_URI'], $match)) {
ob_start();
$type = $match[1];
add_action('init', function () use ($type) {
add_filter("wpseo_sitemap_{$type}_content", function ($xml) {
while (ob_end_clean());
return $xml;
});
});
}
})();