# weglot\_get\_replace\_modify\_link

here the list of pattern we already treat on Weglot:

```php
array(
   'a'         => '/<a([^\>]+?)?href=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
   'datalink'  => '/<([^\>]+?)?data-link=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
   'dataurl'   => '/<([^\>]+?)?data-url=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
   'datacart'  => '/<([^\>]+?)?data-cart-url=(\"|\')([^\s\>]+?)(\"|\')([^\>]+?)?>/',
   'form'      => '/<form([^\>]+?)?action=(\"|\')([^\s\>]+?)(\"|\')/',
   'canonical' => '/<link rel="canonical"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
   'amp'       => '/<link rel="amphtml"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
   'meta'      => '/<meta property="og:url"(.*?)?content=(\"|\')([^\s\>]+?)(\"|\')/',
   'next' => '/<link rel="next"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
   'prev' => '/<link rel="prev"(.*?)?href=(\"|\')([^\s\>]+?)(\"|\')/',
);
```

```php
add_filter( 'weglot_get_replace_modify_link', [] );
```

Here 2 exemples of how to use this filter :<br>

```html
<div data-link2="http://debug-wp-woo.local/shop/">http://debug-wp-woo.local/shop/</div>
```

To translate the link into the attribute data-link-2 you cn use this code :&#x20;

```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;
}
```

Now try with a more complexe case :&#x20;

```html
                <div data-actions="o:click;a:simplelink;target:_self;url:http://debug-wp-woo.local/shop/;">http://debug-wp-woo.local/shop/</div>
```

```php
add_filter( 'weglot_get_replace_modify_link', 'custom_weglot_get_replace_modify_link_2' );
function custom_weglot_get_replace_modify_link_2( $data ) {
	$data['dataactions'] = '/<div[^>]*?data-actions=(["\'].*?url:)([^"\'>]+).*?>(.*?)<\/div>/';
	return $data;
}

function replace_dataactions( $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();
    $sometags = 'div ';
    $quote1 = '"o:click;a:simplelink;target:_self;url:';
    $quote2 = ';"';
	$translated_page  = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-actions=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-actions=' . $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/helpers-functions-1/weglot_get_replace_modify_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.
