maverickM
Hello
i'm using this code to add '/news/' slug to my default posts urls
function custom_post_permalink_structure($permalink, $post) {
if ($post->post_type === 'post' || $post->post_type === 'casinos') {
$language_prefix = '';
if (function_exists('icl_object_id') && function_exists('wpml_get_current_language')) {
$current_language = wpml_get_current_language();
$default_language = wpml_get_default_language();
if ($current_language !== $default_language) {
$language_prefix = $current_language . '/';
}
}
if ($post->post_type === 'post'){
$permalink = home_url($language_prefix . 'news/') . $post->post_name;
}
if ($post->post_type === 'casinos'){
$permalink = home_url($language_prefix) . $post->post_name;
}
}
return $permalink;
}
add_filter('post_link', 'custom_post_permalink_structure', 10, 2);
add_filter('post_type_link', 'custom_post_permalink_structure', 10, 2);
function custom_pre_get_posts($query) {
if (!is_admin() && $query->is_main_query()) {
if (strpos($_SERVER['REQUEST_URI'], '/news/') !== false) {
$query->set('post_type', 'post');
} elseif (!is_page() && !is_archive() && !is_home() && !$query->get('pagename')) {
$query->set('post_type', 'casinos');
}
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
function custom_rewrite_rule() {
add_rewrite_rule('^news/([^/]+)/?$', 'index.php?post_type=post&name=$matches[1]', 'top');
add_rewrite_rule('^([a-z]{2})/([^/]+)/?$', 'index.php?post_type=casinos&name=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite_rule');
but something wrong with alternate links, missing slash. Here is example hidden link
you can find that there is missing slash between '/news' and article url slug
should be hidden link
Laura
WPML Supporter since 05/2018
Languages:
English (English )
Italian (Italiano )
Timezone:
Europe/Rome (GMT+02:00)
Hi, can you tell me from where I can access the post with the wrong URL?
If I go to hidden link and try to open any post the URLs are correctly using the slash