0

I'm currently going through my static template files on a Wordpress-based website using WPML and wondering how I would set this PHP code up to be translatable:

<?php echo preg_replace("/href=\"([^\"]*)\"/", "href=\"$1#activity-filter\"", get_next_posts_link('Next Activities &raquo;')); ?>

Specifically the "Next Activities" text.

Currently I'm wrapping other lines of HTML like so:

<p><?php _e('Words that are being translated', 'roots'); ?></p>

Thanks.

Orangepill
  • 24,500
  • 3
  • 42
  • 63
keitha7
  • 1
  • 4

2 Answers2

0

It would go like:

$translate = __( 'Next Activities &raquo;', 'roots' );
echo preg_replace(
    "/href=\"([^\"]*)\"/", 
    "href=\"$1#activity-filter\"", 
    get_next_posts_link( $translate )
);

Use this approach when the code is too intricate.

Related:

Community
  • 1
  • 1
brasofilo
  • 25,496
  • 15
  • 91
  • 179
  • Awesome thanks. I'll give this a shot and let you know how it works. – keitha7 Jul 12 '13 at 20:48
  • Thanks for the help with this brasofilo. It works beautifully. I just have one question, in the rest of my template files I'm localizing text by: `` When I do the code you helped me out with, and replace `` with `` the code doesn't work. I guess I'm just wondering why? Thanks again! – keitha7 Jul 15 '13 at 11:33
  • The function `_e()` prints (`echo`) the string, whereas `__()` returns the value for you to store/manipulate. Check the documentation: http://codex.wordpress.org/I18n_for_WordPress_Developers. Don't forget to check the page [about] for an introduction to Q&A. And the guide [help], for clearing other doubts. Also, there's a dedicated WP sister site: [wordpress.se] ;) – brasofilo Jul 15 '13 at 11:37
-2

Wordpress does not allow you to include php in your pages by default, however there are plugins such as Exec-PHP which will allow you to do this.

Dolchio
  • 469
  • 2
  • 12
  • As I mentioned, I'm going through my template files (.php files). I'm not doing this directly in the editor window in the backend of Wordpress. Thanks though. – keitha7 Jul 12 '13 at 19:06