# Translate link

### Add method to translate link

By default, Weglot translate link based on some pattern. In the exemple below, we want to translate link in data-link2 attr. To do this we use the weglot\_get\_replace\_modify\_link filter to add a new pattern to our parser.

```php
add_filter( 'weglot_get_replace_modify_link', 'custom_weglot_get_replace_modify_link' );
function custom_weglot_get_replace_modify_link( $data ) {
	$data['datalink2'] = '/<([^\>]+?)?data-link2=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/';
    return $data;
}

function replace_datalink2( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
	$request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
	$replace_url_Service = weglot_get_service( 'Replace_Link_Service_Weglot' );
	$current_language = $request_url_services->get_current_language();
	$translated_page  = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-link2=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-link2=' . $quote1 . $replace_url_Service->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
	return $translated_page;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.weglot.com/wordpress/use-cases/translate-link.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
