Jesus Quintana
Antecedentes del problema:
Estoy intentando generar el sitemap de post de forma correcta en mi sitio web enlace oculto . Estoy utilizando la documentación de GPT, Yoast, y WPML. He implementado varias funciones en mi tema HelloElementor para manejar la reescritura de URLs y la generación de permalinks multilingües. Aquí está parte del código que he utilizado:
<?php
esc_html__( 'Header', 'hello-elementor' ) ] );
register_nav_menus( [ 'menu-2' => esc_html__( 'Footer', 'hello-elementor' ) ] );
}
if ( apply_filters( 'hello_elementor_post_type_support', true ) ) {
add_post_type_support( 'page', 'excerpt' );
}
if ( apply_filters( 'hello_elementor_add_theme_support', true ) ) {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'title-tag' );
add_theme_support(
'html5',
[
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'script',
'style',
]
);
add_theme_support(
'custom-logo',
[
'height' => 100,
'width' => 350,
'flex-height' => true,
'flex-width' => true,
]
);
/*
* Editor Style.
*/
add_editor_style( 'classic-editor.css' );
/*
* Gutenberg wide images.
*/
add_theme_support( 'align-wide' );
/*
* WooCommerce.
*/
if ( apply_filters( 'hello_elementor_add_woocommerce_support', true ) ) {
// WooCommerce in general.
add_theme_support( 'woocommerce' );
// Enabling WooCommerce product gallery features (are off by default since WC 3.0.0).
// zoom.
add_theme_support( 'wc-product-gallery-zoom' );
// lightbox.
add_theme_support( 'wc-product-gallery-lightbox' );
// swipe.
add_theme_support( 'wc-product-gallery-slider' );
}
}
}
}
add_action( 'after_setup_theme', 'hello_elementor_setup' );
function hello_maybe_update_theme_version_in_db() {
$theme_version_option_name = 'hello_theme_version';
// The theme version saved in the database.
$hello_theme_db_version = get_option( $theme_version_option_name );
// If the 'hello_theme_version' option does not exist in the DB, or the version needs to be updated, do the update.
if ( ! $hello_theme_db_version || version_compare( $hello_theme_db_version, HELLO_ELEMENTOR_VERSION, 'register_all_core_location();
}
}
}
add_action( 'elementor/theme/register_locations', 'hello_elementor_register_elementor_locations' );
if ( ! function_exists( 'hello_elementor_content_width' ) ) {
/**
* Set default content width.
*
* @return void
*/
function hello_elementor_content_width() {
$GLOBALS['content_width'] = apply_filters( 'hello_elementor_content_width', 800 );
}
}
add_action( 'after_setup_theme', 'hello_elementor_content_width', 0 );
if ( ! function_exists( 'hello_elementor_add_description_meta_tag' ) ) {
/**
* Add description meta tag with excerpt text.
*
* @return void
*/
function hello_elementor_add_description_meta_tag() {
if ( ! apply_filters( 'hello_elementor_description_meta_tag', true ) ) {
return;
}
if ( ! is_singular() ) {
return;
}
$post = get_queried_object();
if ( empty( $post->post_excerpt ) ) {
return;
}
echo 'post_excerpt ) ) . '">' . "n";
}
}
add_action( 'wp_head', 'hello_elementor_add_description_meta_tag' );
// Admin notice
if ( is_admin() ) {
require get_template_directory() . '/includes/admin-functions.php';
}
// Settings page
require get_template_directory() . '/includes/settings-functions.php';
// Header & footer styling option, inside Elementor
require get_template_directory() . '/includes/elementor-functions.php';
if ( ! function_exists( 'hello_elementor_customizer' ) ) {
// Customizer controls
function hello_elementor_customizer() {
if ( ! is_customize_preview() ) {
return;
}
if ( ! hello_elementor_display_header_footer() ) {
return;
}
require get_template_directory() . '/includes/customizer-functions.php';
}
}
add_action( 'init', 'hello_elementor_customizer' );
if ( ! function_exists( 'hello_elementor_check_hide_title' ) ) {
/**
* Check whether to display the page title.
*
* @param bool $val default value.
*
* @return bool
*/
function hello_elementor_check_hide_title( $val ) {
if ( defined( 'ELEMENTOR_VERSION' ) ) {
$current_doc = ElementorPlugin::instance()->documents->get( get_the_ID() );
if ( $current_doc && 'yes' === $current_doc->get_settings( 'hide_title' ) ) {
$val = false;
}
}
return $val;
}
}
add_filter( 'hello_elementor_page_title', 'hello_elementor_check_hide_title' );
/**
* BC:
* In v2.7.0 the theme removed the `hello_elementor_body_open()` from `header.php` replacing it with `wp_body_open()`.
* The following code prevents fatal errors in child themes that still use this function.
*/
if ( ! function_exists( 'hello_elementor_body_open' ) ) {
function hello_elementor_body_open() {
wp_body_open();
}
}
add_filter('mod_rewrite_rules', 'fix_rewritebase');
function fix_rewritebase($rules){
$home_root = parse_url(home_url());
if ( isset( $home_root['path'] ) ) {
$home_root = trailingslashit($home_root['path']);
} else {
$home_root = '/';
}
$wpml_root = parse_url(get_option('home'));
if ( isset( $wpml_root['path'] ) ) {
$wpml_root = trailingslashit($wpml_root['path']);
} else {
$wpml_root = '/';
}
$rules = str_replace("RewriteBase $home_root", "RewriteBase $wpml_root", $rules);
$rules = str_replace("RewriteRule . $home_root", "RewriteRule . $wpml_root", $rules);
return $rules;
}
add_action( 'generate_rewrite_rules', 'bk_blog_rewrite_rules' );
add_filter('pre_post_link', 'pre_blog_post_link', 10, 3);
add_filter('pre_casestudy_link', 'pre_casestudy_link', 10, 3);
add_filter( 'term_link', 'rewrite_taxonomy_term_permalink', 1, 3);
function bk_blog_rewrite_rules( $wp_rewrite ) {
$new_rules = array(
'resources/(([^/]+/)*blog)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[3]',
'resources/blog/category/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
'resources/blog/category/(.+?)/?$' => 'index.php?category_name=$matches[1]&page=',
'resources/blog/tag/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
'resources/blog/tag/(.+?)/?$' => 'index.php?tag=$matches[1]&page=',
'resources/blog/sector/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?sectors=$matches[1]&paged=$matches[2]',
'resources/blog/sector/([^/]+)/?$' => 'index.php?sectors=$matches[1]&page=',
'resources/blog/([^/]+)/?$' => 'index.php?post_type=post&name=$matches[1]',
'resources/blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'resources/blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'resources/blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'resources/blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'resources/blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
'resources/blog/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'resources/blog/[^/]+/embed/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'resources/blog/([^/]+)/embed/?$' => 'index.php?post_type=post&name=$matches[1]&embed=true',
'resources/blog/[^/]+/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'resources/blog/([^/]+)/trackback/?$' => 'index.php?post_type=post&name=$matches[1]&tb=1',
'resources/blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'resources/blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'resources/blog/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged=$matches[1]',
'resources/blog/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'resources/blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'resources/blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&cpage=$matches[2]',
'resources/blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=post&name=$matches[1]&page=$matches[2]',
'resources/blog/[^/]+/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'resources/blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'resources/blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'resources/blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'resources/blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
'resources/whitepaper/([^/]+)/?$' => 'index.php?post_type=whitepapers&name=$matches[1]',
'resources/whitepaper/?$' => 'index.php?post_type=whitepapers',
'resources/whitepaper/page/?([0-9]{1,})/?$' => 'index.php?post_type=whitepapers&paged=$matches[1]',
'resources/case-study/([^/]+)/?$' => 'index.php?post_type=caso-exito&name=$matches[1]',
'resources/case-study/?$' => 'index.php?post_type=caso-exito',
'resources/case-study/page/?([0-9]{1,})/?$' => 'index.php?post_type=caso-exito&paged=$matches[1]',
'recursos/(([^/]+/)*blog)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[3]&lang=es',
'recursos/blog/category/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]&lang=es',
'recursos/blog/category/(.+?)/?$' => 'index.php?category_name=$matches[1]&page=&lang=es',
'recursos/blog/tag/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]&lang=es',
'recursos/blog/tag/(.+?)/?$' => 'index.php?tag=$matches[1]&page=&lang=es',
'recursos/blog/sector/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?sectors=$matches[1]&paged=$matches[2]&lang=es',
'recursos/blog/sector/([^/]+)/?$' => 'index.php?sectors=$matches[1]&page=&lang=es',
'recursos/blog/([^/]+)/?$' => 'index.php?post_type=post&name=$matches[1]&lang=es',
'recursos/blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&lang=es',
'recursos/blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1&lang=es',
'recursos/blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]&lang=es',
'recursos/blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]&lang=es',
'recursos/blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]&lang=es',
'recursos/blog/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true&lang=es',
'recursos/blog/[^/]+/embed/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true&lang=es',
'recursos/blog/([^/]+)/embed/?$' => 'index.php?post_type=post&name=$matches[1]&embed=true&lang=es',
'recursos/blog/[^/]+/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true&lang=es',
'recursos/blog/([^/]+)/trackback/?$' => 'index.php?post_type=post&name=$matches[1]&tb=1&lang=es',
'recursos/blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]&lang=es',
'recursos/blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]&lang=es',
'recursos/blog/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged=$matches[1]&lang=es',
'recursos/blog/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]&lang=es',
'recursos/blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]&lang=es',
'recursos/blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&cpage=$matches[2]&lang=es',
'recursos/blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=post&name=$matches[1]&page=$matches[2]&lang=es',
'recursos/blog/[^/]+/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&lang=es',
'recursos/blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1&lang=es',
'recursos/blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]&lang=es',
'recursos/blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]&lang=es',
'recursos/blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]&lang=es',
'recursos/whitepaper/([^/]+)/?$' => 'index.php?post_type=whitepapers&name=$matches[1]&lang=es',
'recursos/whitepaper/?$' => 'index.php?post_type=whitepapers&lang=es',
'recursos/whitepaper/page/?([0-9]{1,})/?$' => 'index.php?post_type=whitepapers&paged=$matches[1]&lang=es',
'recursos/caso-exito/([^/]+)/?$' => 'index.php?post_type=caso-exito&name=$matches[1]&lang=es',
'recursos/caso-exito/?$' => 'index.php?post_type=caso-exito&lang=es',
'recursos/caso-exito/page/?([0-9]{1,})/?$' => 'index.php?post_type=caso-exito&paged=$matches[1]&lang=es',
'ressources/(([^/]+/)*blog)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[3]',
'ressources/blog/category/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
'ressources/blog/category/(.+?)/?$' => 'index.php?category_name=$matches[1]&page=',
'ressources/blog/tag/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
'ressources/blog/tag/(.+?)/?$' => 'index.php?tag=$matches[1]&page=',
'ressources/blog/sector/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?sectors=$matches[1]&paged=$matches[2]',
'ressources/blog/sector/([^/]+)/?$' => 'index.php?sectors=$matches[1]&page=',
'ressources/blog/([^/]+)/?$' => 'index.php?post_type=post&name=$matches[1]',
'ressources/blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'ressources/blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'ressources/blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressources/blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressources/blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
'ressources/blog/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'ressources/blog/[^/]+/embed/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'ressources/blog/([^/]+)/embed/?$' => 'index.php?post_type=post&name=$matches[1]&embed=true',
'ressources/blog/[^/]+/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'ressources/blog/([^/]+)/trackback/?$' => 'index.php?post_type=post&name=$matches[1]&tb=1',
'ressources/blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'ressources/blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'ressources/blog/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged=$matches[1]',
'ressources/blog/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'ressources/blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'ressources/blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&cpage=$matches[2]',
'ressources/blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=post&name=$matches[1]&page=$matches[2]',
'ressources/blog/[^/]+/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'ressources/blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'ressources/blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressources/blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressources/blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
'ressources/livre-blanc/([^/]+)/?$' => 'index.php?post_type=whitepapers&name=$matches[1]',
'ressources/livre-blanc/?$' => 'index.php?post_type=whitepapers',
'ressources/livre-blanc/page/?([0-9]{1,})/?$' => 'index.php?post_type=whitepapers&paged=$matches[1]',
'catalog/([^/]+)/?$' => 'index.php?post_type=videojuegos&name=$matches[1]',
'catalog/?$' => 'index.php?post_type=videojuegos',
'catalog/page/?([0-9]{1,})/?$' => 'index.php?post_type=videojuegos&paged=$matches[1]',
'ressources/etude-cas/([^/]+)/?$' => 'index.php?post_type=caso-exito&name=$matches[1]',
'ressources/etude-cas/?$' => 'index.php?post_type=caso-exito',
'ressources/etude-cas/page/?([0-9]{1,})/?$' => 'index.php?post_type=caso-exito&paged=$matches[1]',
'ressourcen/(([^/]+/)*blog)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[3]',
'ressourcen/blog/category/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
'ressourcen/blog/category/(.+?)/?$' => 'index.php?category_name=$matches[1]&page=',
'ressourcen/blog/tag/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
'ressourcen/blog/tag/(.+?)/?$' => 'index.php?tag=$matches[1]&page=',
'ressourcen/blog/sector/([^/]+)?/page/([0-9]+)?/?$' => 'index.php?sectors=$matches[1]&paged=$matches[2]',
'ressourcen/blog/sector/([^/]+)/?$' => 'index.php?sectors=$matches[1]&page=',
'ressourcen/blog/([^/]+)/?$' => 'index.php?post_type=post&name=$matches[1]',
'ressourcen/blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'ressourcen/blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'ressourcen/blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressourcen/blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressourcen/blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
'ressourcen/blog/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'ressourcen/blog/[^/]+/embed/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'ressourcen/blog/([^/]+)/embed/?$' => 'index.php?post_type=post&name=$matches[1]&embed=true',
'ressourcen/blog/[^/]+/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'ressourcen/blog/([^/]+)/trackback/?$' => 'index.php?post_type=post&name=$matches[1]&tb=1',
'ressourcen/blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'ressourcen/blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'ressourcen/blog/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged=$matches[1]',
'ressourcen/blog/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'ressourcen/blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'ressourcen/blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&cpage=$matches[2]',
'ressourcen/blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=post&name=$matches[1]&page=$matches[2]',
'ressourcen/blog/[^/]+/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'ressourcen/blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'ressourcen/blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressourcen/blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'ressourcen/blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
'ressourcen/whitepaper/([^/]+)/?$' => 'index.php?post_type=whitepapers&name=$matches[1]',
'ressourcen/whitepaper/?$' => 'index.php?post_type=whitepapers',
'ressourcen/whitepaper/page/?([0-9]{1,})/?$' => 'index.php?post_type=whitepapers&paged=$matches[1]',
'ressourcen/fallstudie/([^/]+)/?$' => 'index.php?post_type=caso-exito&name=$matches[1]',
'ressourcen/fallstudie/?$' => 'index.php?post_type=caso-exito',
'ressourcen/fallstudie/page/?([0-9]{1,})/?$' => 'index.php?post_type=caso-exito&paged=$matches[1]',
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
/* function pre_blog_post_link($permalink, $post, $leavename) {
global $sitepress;
if ( $post->post_type == 'post') {
$current_lang = $sitepress->get_current_language();
$lang = $current_lang;
switch ($lang) {
case 'es':
$path = '/recursos/blog/';
break;
case 'fr':
$path = '/ressources/blog/';
break;
case 'de':
$path = '/ressourcen/blog/';
break;
default:
$path = '/resources/blog/';
break;
}
$post_name= '%postname%/';
$permalink = '/'. $lang . $path . $post_name;
} else if ( $post->post_type == 'whitepapers') {
$current_lang = $sitepress->get_current_language();
$lang = $current_lang;
switch ($lang) {
case 'es':
$path = '/recursos/whitepaper/';
break;
case 'fr':
$path = '/ressources/livre-blanc/';
break;
case 'de':
$path = '/ressourcen/whitepaper/';
break;
default:
$path = '/resources/whitepaper/';
break;
}
$post_name= '%postname%/';
$permalink = '/'. $lang . $path . $post_name;
} else if ( $post->post_type == 'caso-exito') {
$current_lang = $sitepress->get_current_language();
$lang = $current_lang;
switch ($lang) {
case 'es':
$path = '/recursos/caso-exito/';
break;
case 'fr':
$path = '/ressources/etude-cas/';
break;
case 'de':
$path = '/ressourcen/fallstudie/';
break;
default:
$path = '/resources/case-study/';
break;
}
$post_name= '%postname%/';
$permalink = '/'. $lang . $path . $post_name;
}
else if ( $post->post_type == 'videojuegos') {
$current_lang = $sitepress->get_current_language();
$lang = $current_lang;
switch ($lang) {
case 'es':
$path = '/catalog/';
break;
case 'fr':
$path = '/catalog/';
break;
case 'de':
$path = '/catalog/';
break;
default:
$path = '/catalog/';
break;
}
$post_name= '%postname%/';
$permalink = '/'. $lang . $path . $post_name;
}
return $permalink;
}
function pre_casestudy_link($permalink, $post, $leavename) {
global $sitepress;
if ( $post->post_type == 'caso-exito') {
$current_lang = $sitepress->get_current_language();
$lang = $current_lang;
switch ($lang) {
case 'es':
$path = '/recursos/caso-exito/';
break;
case 'fr':
$path = '/ressources/etude-cas/';
break;
case 'de':
$path = '/ressourcen/fallstudie/';
break;
default:
$path = '/resources/case-study/';
break;
}
$post_name= '%postname%/';
$permalink = '/'. $lang . $path . $post_name;
}
return $permalink;
}
*/
// Reglas de reescritura
add_action('generate_rewrite_rules', function($wp_rewrite) {
$langs = ['es' => 'recursos', 'fr' => 'ressources', 'de' => 'ressourcen'];
$new_rules = [];
foreach ($langs as $lang_code => $lang_path) {
$new_rules["$lang_path/blog/([^/]+)/?$"] = 'index.php?post_type=post&name=$matches[1]&lang=' . $lang_code;
}
// Agrega otras reglas según sea necesario para diferentes tipos de contenido.
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
});
// Generar permalink multilingüe
function generate_permalink_by_type($permalink, $post, $leavename) {
global $sitepress;
// Idiomas y rutas
$paths = [
'post' => [
'es' => '/recursos/blog/',
'fr' => '/ressources/blog/',
'de' => '/ressourcen/blog/',
'default' => '/resources/blog/',
],
'whitepapers' => [
'es' => '/recursos/whitepaper/',
'fr' => '/ressources/livre-blanc/',
'de' => '/ressourcen/whitepaper/',
'default' => '/resources/whitepaper/',
],
];
// Validar tipo de contenido
if (!isset($paths[$post->post_type])) {
return $permalink; // No hacemos nada si no es un tipo soportado
}
// Obtener el idioma actual
$lang = $sitepress->get_current_language() ?: 'default';
// Construir el permalink
$post_name = '%postname%/';
$path = isset($paths[$post->post_type][$lang]) ? $paths[$post->post_type][$lang] : $paths[$post->post_type]['default'];
$permalink = home_url($path . $post_name);
return $permalink;
}
add_filter('pre_post_link', 'generate_permalink_by_type', 10, 3);
add_filter('wpseo_sitemap_entry', function($url, $post) {
global $sitepress;
if ($post->post_type !== 'post') {
return $url;
}
$langs = $sitepress->get_active_languages();
if (!$langs) {
return $url;
}
foreach ($langs as $lang_code => $lang_details) {
$translated_id = apply_filters('wpml_object_id', $post->ID, $post->post_type, false, $lang_code);
if ($translated_id) {
$translated_url = get_permalink($translated_id);
if ($translated_url) {
$url .= '';
}
}
}
return $url;
}, 10, 2);
// Forzar la regeneración de las reglas de reescritura
add_action('init', function() {
if (defined('WP_DEBUG') && WP_DEBUG) {
flush_rewrite_rules(); // Solo para depuración
}
});
/**/
?>
Síntomas:
Al usar las funciones comentadas se genera el sitemap de post SOLO con el partent /recursos/ en todos los idiomas.
Al usar el cod actual, enlace oculto nos da error
Preguntas:
¿Cómo puedo generar correctamente el sitemap de post?
¿Hay algo que deba ajustar en mi configuración actual para que el sitemap funcione con WPML?