WPML
$translated_slug = apply_filters( 'wpml_get_translated_slug', string $slug, string $post_type, string $language_code, string $element_type );
Loại
filter
Phiên bản WPML
3.2.3

Miêu tả

  • Lấy bản dịch slug của loại bài viết hoặc phân loại bằng một ngôn ngữ cụ thể.
  • Giá trị bản dịch được lưu trong WPMLCài đặtDịch loại bài viết.

Đối số

$slug
(string) (Bắt buộc) Giá trị được đặt trong đối số rewrite của hàm register_post_type.
$post_type
(string) (Bắt buộc) Giá trị tham số đầu tiên của hàm register_post_type hoặc register_taxonomy.
$language_code
(string) (Tùy chọn) Trả về bản dịch bằng ngôn ngữ này. Mặc định là NULL, trả về ngôn ngữ hiện tại.
$element_type
(string) (Tùy chọn) Xác định xem slug đã dịch áp dụng cho loại nội dung tùy chỉnh hay phân loại tùy chỉnh. Các giá trị được chấp nhận là post hoặc taxonomy. Mặc định là post.

Ví dụ sử dụng

Ví dụ về loại bài viết
Đăng ký một loại bài viết book với slug tùy chỉnh my-book.

Trong WPMLCài đặtDịch loại bài viết, hãy dịch slug tùy chỉnh sang tiếng Tây Ban Nha với giá trị mi-libro.

Sử dụng hook wpml_get_translated_slug để lấy bản dịch tiếng Tây Ban Nha của slug tùy chỉnh này, đó là mi-libro.

Ví dụ cho wpml_get_translated_slug.
Ví dụ cho wpml_get_translated_slug.
// Register a "book" post type with the custom slug "my-book"
add_action( 'init', 'register_book_init' );
 
function register_book_init() {
    $labels = array(
        'name'               => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
        'singular_name'      => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' )
    );
 
    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'rewrite'            => array( 'slug' => 'my-book' ),
    );
 
    register_post_type( 'book', $args ); 
}
 
// Get the Spanish translation of the post type slug "my-book" 
// This value is saved in WPML->Settings->Post Types Translation
$translated_slug = apply_filters( 'wpml_get_translated_slug', 'my-book', 'book' ,'es' , 'post');
// Return "mi-libro"
echo $translated_slug;

// Register a "genre" custom taxonomy to the "book" custom post type
add_action( 'init', 'register_genre_init', 0 );

function register_genre_init() {
	register_taxonomy( 'genre', 'book', array(
		'rewrite'      => array( 'slug' => 'genre' )
	) );
}
Ví dụ về phân loại
Đăng ký một loại phân loại genre với slug tùy chỉnh genre.

Trong WPMLDịch phân loại, hãy dịch thuật ngữ phân loại sang tiếng Tây Ban Nha với giá trị género.

Sử dụng hook wpml_get_translated_slug để lấy bản dịch tiếng Tây Ban Nha của slug tùy chỉnh này, đó là género.

// Get the Spanish translation of the custom taxonomy slug "genre" 
// This value is saved in WPML->Settings->Taxonomies Translation
$translated_taxonomy_slug = apply_filters( 'wpml_get_translated_slug', 'genre', 'genre' ,'es', 'taxonomy' );
// Return "género"
echo $translated_taxonomy_slug;

wpml_media_url, wpml_media_id, force_suppress_filters, wpml_home_url, wpml_translate_single_string, wpml_translate_string, wpml_elements_without_translations, wpml_permalink, wpml_unfiltered_admin_string, wpml_element_link

Tất cả 12 hook Truy xuất nội dung đã bản địa hóa →