Skip to content

Export: Replace local site URLs with dynamic URLs - #900

Open
TremiDkhar wants to merge 2 commits into
WordPress:trunkfrom
TremiDkhar:issue-805/dynamic-urls
Open

TremiDkhar wants to merge 2 commits into
WordPress:trunkfrom
TremiDkhar:issue-805/dynamic-urls

Conversation

@TremiDkhar

Copy link
Copy Markdown
Contributor

What changed

On export, URLs of the current site in templates, template parts and patterns are replaced with PHP that rebuilds them at runtime, so the theme works on any domain.

  • Theme files: get_template_directory_uri(), or get_stylesheet_directory_uri() for a child theme's own files.
  • Other site URLs: home_url() or site_url(), whichever base matches.

It covers HTML attributes and block comment JSON, and is not tied to any block. Inside "Localize text" output, only link targets (esc_url( '…' )) are converted, so translatable strings stay intact. On by default; pass 'localizeUrls' => false to disable.

Testing

  1. In the Site Editor, add a link to a page on this site and an image from the theme folder to a template, then save.
  2. Create Block Theme → Export Zip.
  3. patterns/<slug>.php uses home_url() / get_template_directory_uri() and contains no local URLs.

Fixes #805

Templates and patterns saved in the Site Editor keep absolute URLs of
the site they were edited on, which break once the theme is installed
on another domain.

On export, URLs of the current site are now replaced with PHP that
rebuilds them at runtime:

- Theme files: get_template_directory_uri(), or
  get_stylesheet_directory_uri() for a child theme's own files.
- Other site URLs: home_url() or site_url(), whichever base matches.

Covers HTML attributes and block comment JSON, including JSON-escaped
URLs. A link written by text localization as esc_url( '...' ) is
converted too; other PHP strings are left untouched so translatable
text stays extractable. Lookalike hosts, other ports and sibling
subdirectory paths are not converted.

Enabled by default through a new localizeUrls export option; pass
'localizeUrls' => false to disable.
@TremiDkhar TremiDkhar changed the title Export: Replace local site URLs with dynamic URLs (#805) Export: Replace local site URLs with dynamic URLs Nov 4, 2026
Cover CBT_Theme_URLs::make_template_urls_local() and the localizeUrls
export option: site and theme URLs in HTML and block comment JSON,
child themes, home_url() vs site_url() bases, URLs that must not be
converted, esc_url() literals from text localization, and the template
and pattern export pipelines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace urls using site_url()

1 participant