wpseo_xml_redirect_sitemap

Redirect /sitemap.xml to /sitemap_index.xml.

Description

wpseo_xml_redirect_sitemap(); 

Usage

  1. if ( !function_exists( 'wpseo_xml_redirect_sitemap' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yoast-seo/inc/wpseo-functions-deprecated.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wpseo_xml_redirect_sitemap(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/inc/wpseo-functions-deprecated.php  
  1. function wpseo_xml_redirect_sitemap() { 
  2. _deprecated_function( __FUNCTION__, 'WPSEO 2.4', 'WPSEO_Sitemaps_Router' ); 
  3.  
  4. $current_url = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://'; 
  5. $current_url .= sanitize_text_field( $_SERVER['SERVER_NAME'] ) . sanitize_text_field( $_SERVER['REQUEST_URI'] ); 
  6.  
  7. // Must be 'sitemap.xml' and must be 404. 
  8. if ( home_url( '/sitemap.xml' ) == $current_url && $GLOBALS[wp_query]->is_404 ) { 
  9. wp_redirect( home_url( '/sitemap_index.xml' ), 301 ); 
  10. exit;