I am working with another developer on a plugin that register and defines a custom type of posts. It's working as intended in the back-end but I would like to change the wording of next article and previous article chunks in the front-end to something like next figure. It must be defined in the plugin, not in the theme.

How can I achieve that ?

edit: In the end I wrote that, alongside the other filters:

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;

But I wish I had used the $format and $link argument of the function instead of a brutal str_replace. But can it be done ?

  • You should be able to tie into the next or previous item hooks however you built the plugin. – Greg McMullen Jun 24 '16 at 13:44
  • I added this in the plugin PHP file (along with some other hooks that work): function next_figures_link() {next_posts_link('Next figure', 'Next figure (2nd argument'), TRUE);} and add_filter('next_posts_link', 'next_figures_link'); But nothing is changed on the front-end. – John Christopher Jun 27 '16 at 10:54

Most likely this is coming from the Theme's language file, can you explain why the translating has to be done by the plugin? Language files are designed for this.

But, if you really want to do this, use the gettext filter:


Using this to much may impact preformance. https://pippinsplugins.com/dangers-gettext-filter/

Regards, Bjorn

  • The plugin must be theme independent because it's going to be used on different wordpres installations that have their own themes set. Can I distribute a generic Theme language file that I could bundle with the plugin and that would be picked up whatever the theme being used ? – John Christopher Jun 27 '16 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.