Title: Using gettext for hyperlinks
Last modified: December 22, 2022

---

# Using gettext for hyperlinks

 *  Resolved [Trelis](https://wordpress.org/support/users/ronantrelis/)
 * (@ronantrelis)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/using-gettext-for-hyperlinks/)
 * I’m trying to localise my plugin and I have a hyperlink with this format:
 *     ```wp-block-code
       <a href="myurl"> Link Text </a>
       ```
   
 * I tried replacing the Link Text as follows:
 *     ```wp-block-code
       <a href="myurl"> __('Link Text','myplugin') </a>
       ```
   
 * but this results in an error.
 * What is the correct approach to localising the link text? Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Faisal Ahammad](https://wordpress.org/support/users/faisalahammad/)
 * (@faisalahammad)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/using-gettext-for-hyperlinks/#post-16313336)
 * Hi [@ronantrelis](https://wordpress.org/support/users/ronantrelis/)
    To localize
   the link text in your plugin, you can use WordPress’s `__()` function. This function
   retrieves the translation of the string and allows you to specify a text domain
   for your plugin.
 * Here’s an example of how you can use it:
 * `<a href="myurl"><?php echo esc_html__('Link Text', 'myplugin'); ?></a>`
 * Use the `esc_html__()` function to escape the output and prevent security vulnerabilities.
 * You will also need to create a translation file for your plugin, which contains
   the translations of the strings used in your plugin. The translation file should
   be placed in your plugin’s `languages` folder and have the following naming convention:`{
   text-domain}-{locale}.mo`. For example, the translation file for the myplugin
   text domain in the English (US) locale would be named `myplugin-en_US.mo`.
 * You can use a plugin like [Poedit](https://poedit.net/) to create and manage 
   your translation files.
 * I hope this helps! Let me know if you have any questions.`
    -  This reply was modified 3 years, 5 months ago by [Faisal Ahammad](https://wordpress.org/support/users/faisalahammad/).
      Reason: fixed typo error
 *  Thread Starter [Trelis](https://wordpress.org/support/users/ronantrelis/)
 * (@ronantrelis)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/using-gettext-for-hyperlinks/#post-16313445)
 * Many thanks [@faisalahammad](https://wordpress.org/support/users/faisalahammad/),
   very helpful.
 * Here’s what I have now:[](https://docs.trelis.com/features/trelis-prime)
 *     ```wp-block-code
       'description' => '<a href="https://docs.trelis.com/features/trelis-prime"><?php echo esc_html__('Learn how to minimise payment processing charges', 'trelis-crypto-payments'); ?></a>',
       ```
   
 * and here’s the error I’m getting:
 * **Parse error**: syntax error, unexpected ‘Learn’ (T_STRING), expecting ‘)’ in**/
   home/customer/www/mysite.com/public_html/wp-content/plugins/Trelis-ethereum-payment-
   gateway.php_/Trelis-ethereum-payment-gateway.php** on line **190**
 *  [Faisal Ahammad](https://wordpress.org/support/users/faisalahammad/)
 * (@faisalahammad)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/using-gettext-for-hyperlinks/#post-16313866)
 * Hi [@ronantrelis](https://wordpress.org/support/users/ronantrelis/)
    It looks
   like there is an issue with the PHP code in your plugin file. The problem is 
   that you are trying to use PHP tags and functions inside a single-quoted string,
   which is not allowed.
 * To fix the issue, you will need to either use double quotes to define the string
   or concatenate the string and the PHP code using the `.` operator:
 * **Option 1:**
    `'description' => "<a href='https://docs.trelis.com/features/trelis-
   prime'>" . esc_html__('Learn how to minimise payment processing charges', 'trelis-
   crypto-payments') . "</a>",`
 * **Option 2:**
    `'description' => '<a href="https://docs.trelis.com/features/trelis-
   prime">' . esc_html__('Learn how to minimise payment processing charges', 'trelis-
   crypto-payments') . '</a>',`
 * Either of these options should resolve the parse error you are seeing.
 * I hope this helps! Let me know if you have any other questions.
 *  Thread Starter [Trelis](https://wordpress.org/support/users/ronantrelis/)
 * (@ronantrelis)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/using-gettext-for-hyperlinks/#post-16313925)
 * This was incredibly helpful. I appreciate it a lot Faisal, thanks, Ronan

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Using gettext for hyperlinks’ is closed to new replies.

## Tags

 * [gettext](https://wordpress.org/support/topic-tag/gettext/)
 * [internationalization](https://wordpress.org/support/topic-tag/internationalization/)
 * [language](https://wordpress.org/support/topic-tag/language/)
 * [localisation](https://wordpress.org/support/topic-tag/localisation/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 2 participants
 * Last reply from: [Trelis](https://wordpress.org/support/users/ronantrelis/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/using-gettext-for-hyperlinks/#post-16313925)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
