Skip to content

Themes: Show Preview button for block themes on Add Themes screen#11184

Open
sanketio wants to merge 1 commit intoWordPress:trunkfrom
sanketio:fix/64729
Open

Themes: Show Preview button for block themes on Add Themes screen#11184
sanketio wants to merge 1 commit intoWordPress:trunkfrom
sanketio:fix/64729

Conversation

@sanketio
Copy link

@sanketio sanketio commented Mar 6, 2026

Description

After installing a block theme from Appearance → Themes → Add New Theme, the "Preview" button was missing — only "Activate" appeared. Classic themes correctly showed both "Activate" and "Live Preview". This inconsistency was present across all tabs and search results.

The root cause is threefold:

  1. wp_ajax_install_theme() was always sending customizeUrl pointing to the classic Customizer (customize.php) for all themes, including block themes. Block themes don't support the Customizer, so the button was either broken or absent.

  2. wp_ajax_query_themes() (the on-load data for all theme cards) was sending site-editor.php for installed block themes, but without the wp_theme_preview=<slug> query parameter. Without it, clicking Preview would open the Site Editor for the currently active theme instead of the selected one.

  3. The Underscore.js template in theme-install.php had a blanket <# if ( ! data.block_theme ) { #> guard added by #54878 in 2022 to prevent pointing block themes at the Customizer. That suppression was never updated after context-aware Site Editor preview URLs became available.


Changes

wp-admin/includes/ajax-actions.php — two functions:

  • wp_ajax_install_theme(): For block themes, sends site-editor.php?wp_theme_preview=<slug>&return=... instead of the classic Customizer URL. Mirrors the existing logic in class-theme-installer-skin.php used by the non-AJAX full-page install path. Capability check also broadened to allow block themes regardless of the customize cap.
  • wp_ajax_query_themes(): Adds wp_theme_preview=<slug> to the Site Editor URL for already-installed block themes shown on page load, so the button actually previews the correct theme.

wp-admin/theme-install.php:

  • Replaces the blanket block-theme suppression with an explicit branch: block themes render a plain Preview link (no load-customize); classic themes keep Live Preview with load-customize.

js/_enqueues/wp/updates.js:

  • installThemeSuccess(): Checks response.blockTheme when replacing the .preview button post-install. Block themes get a plain Preview <a> without the load-customize class (which triggers Customizer-specific JS); classic themes are unchanged.

Testing Instructions

Prerequisites: A WordPress install with at least one classic theme and one block theme available but not yet installed.

Block theme — AJAX install path

  1. Go to Appearance → Themes → Add New Theme.
  2. Search for a block theme (e.g. "Twenty Twenty-Four") or open the Block Themes tab.
  3. Click Install on any block theme that is not yet installed.
  4. Wait for installation to complete.
  5. Both Activate and Preview buttons should appear immediately.
  6. Click Preview — it should open the Site Editor with that theme previewed, not the Customizer.

Classic theme — AJAX install path

  1. On the same screen, install a classic theme (e.g. "Twenty Twenty").
  2. Both Activate and Live Preview buttons should appear.
  3. Click Live Preview — it should open the Customizer with that theme.

Already-installed block theme cards (page-load path)

  1. Install a block theme via any method and do not activate it.
  2. Return to Appearance → Themes → Add New Theme and browse any tab.
  3. Find the installed block theme card.
  4. The card should show Activate and Preview.
  5. Click Preview — it should open the Site Editor previewing that specific theme, not the currently active one.

No regression — full-page install path

  1. Navigate directly to wp-admin/update.php?action=install-theme&theme=<slug> (non-AJAX install).
  2. Post-install buttons remain correct — this path was already working via class-theme-installer-skin.php.

Active block theme

  1. Activate a block theme.
  2. Go to Add New Theme and find the active theme's card.
  3. It should show Activated (disabled) and Customize (linking to the Site Editor) — unchanged behaviour.

Trac ticket: https://core.trac.wordpress.org/ticket/64729


Use of AI Tools


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sanketparmar.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

1 participant