0

I can't seem to work my way around this: I have included a string translation into my functions.php file, Polylang registered it in the admin panel and I have added my translations for both Croatian and English.

When using the pll_e('saznaj-vise') function the output is fine in both languages (Saznaj Više and Read More), however when I include this string translation into my function modify_read_more_link() it does not display the permalink to the post/page, just static text above the content.

My code in functions.php looks like this:

function modify_read_more_link() {
  return  '<a href="' . get_permalink() . '">' . pll_e('saznaj-vise') . '</a>';
{

  add_filter( 'the_content_more_link', 'modify_read_more_link' );

  pll_register_string('read-more', 'saznaj-vise', 'Wordpress');

The code inside the loop (for displaying a page) looks like this:

<div>
  <?php global $more; $more = 0; ?>
  <p>
  <?php the_content(pll_get_post(5)); ?>
  </p>

What I would like is that my string translation becomes a permalink to the post/page on the desired cutoff, as usual in WordPress. I'd really appreciate some help. Thank you!

Pasko
  • 21
  • 1
  • 2

1 Answers1

2

SOLVED!

This should be useful to anyone who wants to translate the Read More string, as the information online is quite hard to find. The working code in functions.php looks like this:

function modify_read_more_link() {
  return  '<a href="' . get_permalink() . '">' . pll__('string translation') .  '</a>';
}

add_filter( 'the_content_more_link', 'modify_read_more_link' );
pll_register_string('my-theme', 'string translation');

The problem was that the pll_e(string-translation) didn't work inside function modify_read_more_link() { instead we needed the polylang function which returns the translated string - the one with two underscores: pll__('string translation')

Simply replace 'string translation' with the name of your string and translate it inside the wordpress admin panel.

Polylang function reference sheet

Pasko
  • 21
  • 1
  • 2