Title: Uri::withPath
Published: May 20, 2026
Last modified: August 20, 2026

---

# Uri::withPath( $path ): static

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uri/withpath/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uri/withpath/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uri/withpath/?output_format=md#related)

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uri/withpath/?output_format=md#return)󠁿

 static

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uri/withpath/?output_format=md#source)󠁿

    ```php
    public function withPath($path): UriInterface
    {
        if ($this->path === $path = $this->filterPath($path)) {
            return $this;
        }
        $new = clone $this;
        $new->path = $path;
        return $new;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/third-party/nyholm/psr7/uri.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/Uri.php#L182)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/Uri.php#L182-L190)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uri/withpath/?output_format=md#related)󠁿

| Uses | Description | 
| [Uri::filterPath()](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-uri/filterpath/)`wp-includes/php-ai-client/third-party/Nyholm/Psr7/Uri.php` |  |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclientdependencies-nyholm-psr7-uri%2Fwithpath%2F)
before being able to contribute a note or feedback.