sitemap
This commit is contained in:
@@ -17,6 +17,97 @@ function sev_tort_query_vars( $vars ) {
|
||||
return $vars;
|
||||
}
|
||||
|
||||
add_action( 'template_redirect', 'sev_tort_static_seo_files', 0 );
|
||||
function sev_tort_static_seo_files() {
|
||||
$path = isset( $_SERVER['REQUEST_URI'] ) ? parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : '';
|
||||
$path = trim( (string) $path, '/' );
|
||||
|
||||
if ( 'sitemap_index.xml' === $path ) {
|
||||
sev_tort_send_sitemap_index();
|
||||
}
|
||||
|
||||
if ( 'sitemap.xml' === $path ) {
|
||||
sev_tort_send_sitemap();
|
||||
}
|
||||
|
||||
if ( 'robots.txt' === $path ) {
|
||||
sev_tort_send_robots();
|
||||
}
|
||||
}
|
||||
|
||||
function sev_tort_send_sitemap_index() {
|
||||
status_header( 200 );
|
||||
header( 'Content-Type: application/xml; charset=UTF-8' );
|
||||
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
|
||||
echo "\t" . '<sitemap>' . "\n";
|
||||
echo "\t\t" . '<loc>' . esc_url( home_url( '/sitemap.xml' ) ) . '</loc>' . "\n";
|
||||
echo "\t\t" . '<lastmod>' . esc_html( gmdate( 'Y-m-d' ) ) . '</lastmod>' . "\n";
|
||||
echo "\t" . '</sitemap>' . "\n";
|
||||
echo '</sitemapindex>';
|
||||
exit;
|
||||
}
|
||||
|
||||
function sev_tort_send_sitemap() {
|
||||
status_header( 200 );
|
||||
header( 'Content-Type: application/xml; charset=UTF-8' );
|
||||
|
||||
$pages = sev_tort_pages();
|
||||
$urls = array(
|
||||
array(
|
||||
'loc' => home_url( '/' ),
|
||||
'changefreq' => 'weekly',
|
||||
'priority' => '1.0',
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $pages as $page ) {
|
||||
if ( empty( $page['indexable'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$priority = in_array( $page['slug'], array( 'torty-na-zakaz', 'bento', 'detskie', 'svadebnye', 'na-den-rozhdeniya', 'ceny' ), true ) ? '0.9' : '0.8';
|
||||
|
||||
$urls[] = array(
|
||||
'loc' => home_url( '/' . $page['slug'] . '/' ),
|
||||
'changefreq' => 'weekly',
|
||||
'priority' => $priority,
|
||||
);
|
||||
}
|
||||
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
|
||||
|
||||
foreach ( $urls as $url ) {
|
||||
echo "\t" . '<url>' . "\n";
|
||||
echo "\t\t" . '<loc>' . esc_url( $url['loc'] ) . '</loc>' . "\n";
|
||||
echo "\t\t" . '<lastmod>' . esc_html( gmdate( 'Y-m-d' ) ) . '</lastmod>' . "\n";
|
||||
echo "\t\t" . '<changefreq>' . esc_html( $url['changefreq'] ) . '</changefreq>' . "\n";
|
||||
echo "\t\t" . '<priority>' . esc_html( $url['priority'] ) . '</priority>' . "\n";
|
||||
echo "\t" . '</url>' . "\n";
|
||||
}
|
||||
|
||||
echo '</urlset>';
|
||||
exit;
|
||||
}
|
||||
|
||||
function sev_tort_send_robots() {
|
||||
status_header( 200 );
|
||||
header( 'Content-Type: text/plain; charset=UTF-8' );
|
||||
|
||||
echo "User-agent: *\n";
|
||||
echo "Disallow: /wp-admin/\n";
|
||||
echo "Allow: /wp-admin/admin-ajax.php\n";
|
||||
echo "Disallow: /wp-includes/\n";
|
||||
echo "Disallow: /wp-content/plugins/\n";
|
||||
echo "Disallow: /wp-content/cache/\n";
|
||||
echo "Disallow: /wp-json/\n";
|
||||
echo "Disallow: /*?s=\n\n";
|
||||
echo 'Sitemap: ' . esc_url( home_url( '/sitemap.xml' ) ) . "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
add_action( 'template_redirect', 'sev_tort_route_status' );
|
||||
function sev_tort_route_status() {
|
||||
if ( sev_tort_current_page_config() ) {
|
||||
|
||||
Reference in New Issue
Block a user