Last active
December 25, 2019 09:43
-
-
Save RiodeJaneiroo/2ed71935e31a0cd9335ebffc76bc7361 to your computer and use it in GitHub Desktop.
[Сделать sitemap.html] к обычной странице добавляет .html #wordpress #seo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('pll_translation_url', 'check_archive_translation', 10, 2); | |
function check_archive_translation($url, $lang) { | |
$posSearch = strpos($url, '/sitemap/'); | |
$posSearchUK = strpos($url, 'uk/karta-sajtu/'); | |
if($posSearch !== false) { | |
$url = site_url() . '/sitemap.html'; | |
} else if ($posSearchUK !== false) { | |
$url = site_url() . '/uk/sitemap.html'; | |
} | |
return $url; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'request', 'add_sitemap_html' ); | |
function add_sitemap_html( $query_vars ) { | |
// Проверяем, запрошена ли страница sitemap.html | |
if ( isset( $query_vars['name'] ) && $query_vars['name'] == 'sitemap.html' ) { | |
// Подменяем запрос данными от страницы со slug = sitemap | |
$query_vars = [ | |
'page' => '', | |
'pagename' => 'sitemap', | |
]; | |
// Удаляем перенаправление на url со слешем на конце | |
remove_action( 'template_redirect', 'redirect_canonical' ); | |
remove_action( 'wpseo_canonical', 'wrong_url_redirect' ); | |
} else if (isset( $query_vars['pagename'] ) && $query_vars['pagename'] == 'sitemap' ) { | |
wp_redirect( home_url() . '/sitemap.html', 301 ); | |
exit; | |
} | |
return $query_vars; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function structure_sitemap_html_seo($query_vars) { | |
$langPlug = 'wpml'; // wpml | polylang | false | |
$langUa = 'ua'; | |
$pageSitemap = 'sitemap'; | |
$pageSitemapUa = 'sitemapua'; | |
$currentLang = (defined('ICL_LANGUAGE_CODE')) ? ICL_LANGUAGE_CODE : $query_vars['lang']; | |
// var_dump($query_vars); | |
// Проверяем, запрошена ли страница sitemap.html | |
if ( isset( $query_vars['category_name'] ) && $query_vars['category_name'] == 'sitemap.html') { | |
// Подменяем запрос данными от страницы со slug = sitemap | |
if($langPlug == 'wpml') { | |
if(($currentLang == $langUa)) { | |
$query_vars = ['page' => '','pagename' => $pageSitemapUa]; | |
if($langPlug == 'polylang') $query_vars['lang'] = $langUa; | |
} else { | |
$query_vars = ['page' => '','pagename' => $pageSitemap]; | |
} | |
} | |
// Удаляем перенаправление на url со слешем на конце | |
remove_action( 'template_redirect', 'redirect_canonical' ); | |
remove_action( 'wpseo_canonical', 'wrong_url_redirect' ); | |
} else if(isset( $query_vars['pagename'] ) && ($query_vars['pagename'] == $pageSitemap || $query_vars['pagename'] == $pageSitemapUa)) { | |
// Делаем перенаправления со старых страниц | |
$pageRedirectUrl = ($langPlug == 'polylang') ? home_url() .'/'.$langUa .'/sitemap.html' : home_url() . '/sitemap.html'; | |
wp_safe_redirect($pageRedirectUrl, 301 ); | |
exit; | |
} | |
return $query_vars; | |
} | |
add_action( 'request', 'structure_sitemap_html_seo' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment