Palladi_N
@Palladi_N
Web dev

Url — site.com/360 — Wordpress / Как обойти ограничение назначения url?

Не могу создать url страницы по примеру site.com/360
Нашел информацию что WP блокирует и переназначает на(в примере site.com/360-2)

Кто сталкивался и возможно решил вопрос?
Так же используется WPML то есть нужно и site.com/en/360, site.com/ru/360....
  • Вопрос задан
  • 88 просмотров
Решения вопроса 1
Palladi_N
@Palladi_N Автор вопроса
Web dev
В общем для решения этого вопроса с самим WP нужно добавить код в functions.php

add_filter( 'wp_unique_post_slug', 'mg_unique_post_slug', 10, 6 );

/**
* Allow numeric slug
*
* @param string $slug The slug returned by wp_unique_post_slug().
* @param int $post_ID The post ID that the slug belongs to.
* @param string $post_status The status of post that the slug belongs to.
* @param string $post_type The post_type of the post.
* @param int $post_parent Post parent ID.
* @param string $original_slug The requested slug, may or may not be unique.
*/
function mg_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
global $wpdb;

// don't change non-numeric values
if ( ! is_numeric( $original_slug ) || $slug === $original_slug ) {
return $slug;
}

// Was there any conflict or was a suffix added due to the preg_match() call in wp_unique_post_slug() ?
$post_name_check = $wpdb->get_var( $wpdb->prepare(
"SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1",
$original_slug, $post_type, $post_ID, $post_parent
) );

// There really is a conflict due to an existing page so keep the modified slug
if ( $post_name_check ) {
return $slug;
}

// Return our numeric slug
return $original_slug;
}

Для обхода WPML что бы эта функция срабатывала нужно в файле плагина "wpml-slug-filter.class.php" закоментировать строки(106-111):

$suffix = 2;
do {
$alt_post_name = substr ( $slug, 0, 200 - ( strlen ( $suffix ) + 1 ) ) . "-$suffix";
$suffix ++;
} while ( $this->post_slug_exists ( $post_id, $post_language, $alt_post_name, $post_type, $post_parent ) );
$slug = $alt_post_name;
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Если я правильно понял вопрос, то добавить в functions.php
add_filter('category_link', function($a){
	return str_replace( 'category/', '', $a );
}, 99 );

это избавит Вас от слова категория.
Нужно вложение, делайте родителя, т.е. создайте страницу ru, затем создайте страницу 360, у которой родитель ru
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы