> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/cms/wordpress/helpers-functions-1/get_replace_modify_link_in_xml.md).

# get\_replace\_modify\_link\_in\_xml

This filter allow you to add pattern to define kind of link you want to translate in xml.

here the list of pattern we already treat on Weglot:

```php
array('loc' => '/<loc>(.*?)<\/loc>/');
```

The filter receives this array and must return it. Each key you add needs a global function named `replace_<key>( $translated_page, $current_url )`: Weglot calls it for every URL the pattern captures (its first capture group) and uses the page it returns. Without that function the pattern is ignored. Rename the function with the `weglot_modify_link_sitemap_replace_function` filter.

```php
add_filter( 'get_replace_modify_link_in_xml', 'custom_weglot_xml_link_patterns' );
function custom_weglot_xml_link_patterns( $patterns ) {
    $patterns['page_loc'] = '/<page:loc>([^<]+)<\/page:loc>/';
    return $patterns;
}

function replace_page_loc( $translated_page, $current_url ) {
    $replace_link_service = weglot_get_service( 'Replace_Link_Service_Weglot' );
    $current_language     = weglot_get_service( 'Request_Url_Service_Weglot' )->get_current_language();

    return str_replace(
        '<page:loc>' . $current_url . '</page:loc>',
        '<page:loc>' . esc_url( $replace_link_service->replace_url( $current_url, $current_language ) ) . '</page:loc>',
        $translated_page
    );
}
```

{% hint style="warning" %}
Only target tags holding page URLs. File URLs (images, PDF…) are skipped, and the `<xhtml:link rel="alternate">` tags of a sitemap are its hreflang cluster: rewriting them to the current language would break it.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.weglot.com/cms/wordpress/helpers-functions-1/get_replace_modify_link_in_xml.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
