Skip navigation

Это форум технической поддержки WPML – плагина для многоязычной WordPress.

Доступно для чтения всем, но только клиенты, купившие WPML, могут оставлять сообщения. Сотрудники WPML отвечают на сообщения форума 6 дней в неделю, 22 часов в сутки.

Сотрудники Службы поддержки сегодня не доступны на форуме Russian. Создайте обращение и мы возьмемся за решение вашего вопроса, как только будем в сети. Благодарим за понимание.

Помечено: 

Эта тема содержит 1 ответ, имеет 2 голоса.

Последнее обновление: Andrey 3 недели назад.

При содействии: Andrey.

Автор Записи
30 августа, 2024 на 9:57 дп #16124065

Андрей Косолапов

Предыстория вопроса:
I am currently managing a bilingual blog using the WPML plugin at скрытая ссылка. I first create a post in the default language with a URL like site.com/test-post. Then, I create a translation of this post into another language, such as Russian, which by default becomes site.com/ru/testoviy-post. I manually change this URL to match the original, resulting in site.com/ru/test-post. I have tried using the following code to automate this process:

add_action('wpml_save_post_translation', 'wpml_custom_slug_for_translations', 10, 3);

function wpml_custom_slug_for_translations($translation_id, $lang, $post_id) {
$original_post_id = apply_filters('wpml_object_id', $translation_id, get_post_type($translation_id), false, wpml_get_default_language());

if ($original_post_id) {
$original_slug = get_post_field('post_name', $original_post_id);

if ($original_slug) {
$translated_post_data = array(
'ID' => $translation_id,
'post_name' => $original_slug
);

wp_update_post($translated_post_data);
}
}
}

Unfortunately, this solution did not work on my custom theme, nor on the default Twenty Twenty-Four theme.

Симптомы:
The provided code did not work on my custom theme or the default Twenty Twenty-Four theme.

Вопросы:
Is there any built-in functionality within WPML to automate the URL structure for translated posts?
Is there a specific hook or filter in WPML that I can use to achieve this automatically?

31 августа, 2024 на 10:35 дп #16127302

Andrey
Supporter

Языки: Английский (English ) Русский (Русский )

Часовой пояс: Europe/Kyiv (GMT+03:00)

Спасибо за обращение в службу поддержки WPML.

Всю доступную информацию для разработчиков, Вы можете видеть здесь:
https://wpml.org/documentation/support/

Справочник по хукам WPML:
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

Вы также можете активировать опцию Translate (this will include the slug in the translation and not create it automatically from the title) в WPML → Settings → Translated documents options. То есть, при переводе страницы слаг будет добавлен на перевод (а не сгенерирован автоматически с заголовка), где Вы сможете его скопировать с оригинала.

Этот тикет теперь закрыт. Если Вы являетесь клиентом WPML и Вам нужна соответствующая помощь, пожалуйста, откройте новый тикет поддержки.