-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml-sitemap-feed-companion.php
41 lines (35 loc) · 1.18 KB
/
xml-sitemap-feed-companion.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
36
37
38
39
40
41
<?php
/*
Plugin Name: XML Sitemap Feed Companion
Plugin URI: http://tonykwon.com/wordpress-plugins/xml-sitemap-feed-companion/
Description: This plugin is a companion tool for <a href="http://4visions.nl/en/wordpress-plugins/xml-sitemap-feed/">XML Sitemap Feed</a> by RavanH. This plugin basically disables WordPress Canonical Redirect Filter on virtual URL /sitemap.xml
Version: 0.1
Author: Tony Kwon
Author URI: http://tonykwon.com/wordpress-plugins/xml-sitemap-feed-companion/
License: GPLv3
*/
add_action( 'parse_request', 'disable_canonical_redirects_on_virtual_url' );
function disable_canonical_redirects_on_virtual_url( $query )
{
/* PHP 5.2 and higher */
$q = filter_input( INPUT_GET, 'q', FILTER_SANITIZE_STRING );
switch( $q )
{
case '/sitemap.xml/':
/* redirect to sitemap.xml */
wp_redirect( '/sitemap.xml', 301 );
exit;
break;
case '/robots.txt/':
/* redirect to sitemap.xml */
wp_redirect( '/robots.txt', 301 );
exit;
break;
case '/sitemap.xml':
case '/robots.txt':
/* remove the Canonical Redirect filter */
remove_filter( 'template_redirect', 'redirect_canonical' );
break;
}
return $query;
}