对于插件注册的自定义类型,如何更改前端`下一篇文章`的措辞?

时间:2016-06-24 作者:John Christopher

我正在与另一位开发人员合作开发一个插件,该插件可以注册并定义自定义类型的帖子。它在后端按预期工作,但我想更改next articleprevious article 前端的块next figure. 它必须在插件中定义,而不是在主题中定义。

我如何才能做到这一点?

编辑:最后,我写道,与其他过滤器一起:

add_filter(\'next_post_link\', \'next_figure_link\');
function next_figure_link($arg) {
  if (get_post_type() == \'ct_figure\') {
    $arg = str_replace(\'Next Article\', \'Next figure\', $arg);}
  return $arg;
}
add_filter(\'previous_post_link\', \'previous_figure_link\');
function previous_figure_link($arg) {
  if (get_post_type() == \'ct_figure\') {
    $arg = str_replace(\'Previous article\', \'Previous figure\', $arg);}
  return $arg;
}
但我希望我用过$format$link 函数的参数,而不是str_replace. 但这能做到吗?

1 个回复
SO网友:Bjorn

这很可能来自主题的语言文件,你能解释一下为什么翻译必须由插件完成吗?语言文件就是为此而设计的。

但是,如果确实要这样做,请使用gettext过滤器:

https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext

使用这一点可能会影响性能。https://pippinsplugins.com/dangers-gettext-filter/

你好,比约恩

相关推荐