admin管理员组文章数量:1122846
I tryed this code but the german version is not working (italian is ok)
$lang = substr( get_locale(), 0, 2 );
global $post;
if ('it' != $lang ) {
$term_name = get_the_terms(get_the_ID(), 'intro_'.$lang)[0]->name;
} else
$term_name = get_the_terms (get_the_ID(), 'intro')[0]->name;
the line with 'intro_'.$lang
breaks the posts layout, any solution?
I tryed this code but the german version is not working (italian is ok)
$lang = substr( get_locale(), 0, 2 );
global $post;
if ('it' != $lang ) {
$term_name = get_the_terms(get_the_ID(), 'intro_'.$lang)[0]->name;
} else
$term_name = get_the_terms (get_the_ID(), 'intro')[0]->name;
the line with 'intro_'.$lang
breaks the posts layout, any solution?
2 Answers
Reset to default 0Here you are dealing with 2 taxonomy
for getting the term name
which is wrong.
You just need to do this
`$term_name = get_the_terms (get_the_ID(), 'intro')[0]->name;`
Once you get the $term_name then you can apply your locale to display it.
<?php echo __( $term_name, 'YOUR_DOMAIN' );
you are trying to access the term name in a different language. Instead of directly accessing the term name using the language code concatenated with the taxonomy name, you should consider using the wp functions provided for translation.
global $post;
// Get the current language
$lang = substr(get_locale(), 0, 2);
// Get the terms for the appropriate taxonomy
$terms = ($lang != 'it') ? get_the_terms(get_the_ID(), 'intro_' . $lang) : get_the_terms(get_the_ID(), 'intro');
// Check if terms are available
if ($terms && !is_wp_error($terms)) {
// Get the first term
$term = reset($terms);
// Get the translated term name
$term_name = $term->name;
} else {
$term_name = ''; // Handle case where terms are not available
}
// Output the term name
echo $term_name;
本文标签: phptranslating a custom taxonomy term in a shortcode
版权声明:本文标题:php - translating a custom taxonomy term in a shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311676a1934825.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论