$page ) {
add_rewrite_rule( '^' . preg_quote( $slug, '/' ) . '/?$', 'index.php?sev_tort_page=' . $slug, 'top' );
}
}
add_filter( 'query_vars', 'sev_tort_query_vars' );
function sev_tort_query_vars( $vars ) {
$vars[] = 'sev_tort_page';
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 '' . "\n";
echo '' . "\n";
echo "\t" . '' . "\n";
echo "\t\t" . '' . esc_url( home_url( '/sitemap.xml' ) ) . '' . "\n";
echo "\t\t" . '' . esc_html( gmdate( 'Y-m-d' ) ) . '' . "\n";
echo "\t" . '' . "\n";
echo '';
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 '' . "\n";
echo '' . "\n";
foreach ( $urls as $url ) {
echo "\t" . '' . "\n";
echo "\t\t" . '' . esc_url( $url['loc'] ) . '' . "\n";
echo "\t\t" . '' . esc_html( gmdate( 'Y-m-d' ) ) . '' . "\n";
echo "\t\t" . '' . esc_html( $url['changefreq'] ) . '' . "\n";
echo "\t\t" . '' . esc_html( $url['priority'] ) . '' . "\n";
echo "\t" . '' . "\n";
}
echo '';
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() ) {
status_header( 200 );
}
}
add_filter( 'template_include', 'sev_tort_template_include' );
function sev_tort_template_include( $template ) {
$page = sev_tort_current_page_config();
if ( ! $page ) {
return $template;
}
if ( 'politika-konfidencialnosti' === $page['slug'] ) {
return get_stylesheet_directory() . '/page-templates/page-policy.php';
}
if ( 'portfolio' === $page['slug'] ) {
return get_stylesheet_directory() . '/page-templates/page-portfolio.php';
}
return get_stylesheet_directory() . '/page-templates/page-service.php';
}
function sev_tort_current_page_config() {
$slug = get_query_var( 'sev_tort_page' );
if ( ! $slug && is_front_page() ) {
return false;
}
if ( ! $slug && is_page() ) {
$slug = get_post_field( 'post_name', get_queried_object_id() );
}
$pages = sev_tort_pages();
return isset( $pages[ $slug ] ) ? $pages[ $slug ] : false;
}