WordPress使用子主题中languages

使用子主题的目的

WordPress可以通过创建一个非常基本的子主题 来对一个父主题的样式和布局进行修改和扩展,而不需要对父主题的文件作任何修改。通过这样的方式,当父主题被更新的时候,您所做的修改就可以保存下来。

子主题制作参考

https://codex.wordpress.org/zh-cn:子主题

WordPress使用子主题中languages

假设您将语言文件放置在languages子主题内的文件夹中,以下代码将告诉WordPress为您的子主题加载单独的语言文件:

add_action( 'after_setup_theme', 'theme_child_setup' );function theme_child_setup() { /* Load the child theme's gettext file */ load_child_theme_textdomain( 'textdomain', get_stylesheet_directory() . '/languages' );}

上面的代码进入你的子主题functions.php文件。替换textdomain为您使用的实际文本域。

关于以上的textdomain值

1、可以在父主题中搜索 load_theme_textdomain,如果发现以下代码:

load_theme_textdomain( 'framework', get_template_directory() . '/languages' );

那么textdomain值为framework

2、也可以在模板文件中翻译语句,如:

__( 'Theme Options', 'theme-textdomain' )

那么textdomain值为theme-textdomain

3、如果有多个textdomain,也可以直接添加,如:

add_action( 'after_setup_theme', 'theme_child_setup' );function theme_child_setup() { /* Load the child theme's gettext file */ load_child_theme_textdomain( 'textdomain1', get_stylesheet_directory() . '/languages' ); load_child_theme_textdomain( 'textdomain2', get_stylesheet_directory() . '/languages' );}
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: