This is a feature plugin intended to implement #28536: Add browser history and deep linking for navigation in Customizer preview
This plugin keeps the Customizer URL in the browser updated with current previewed URL as the
url query param and current expanded panel/section/control as
autofocus params. This allows for bookmarking and also the ability to reload and return go the same view (which is great for developers), including which device you are previewing (desktop, tablet, or mobile). Not only will the URL be kept in sync with the current customizer UI, but new browser history entries will be added as you navigate around the site in the preview (via
history.pushState()), allowing you to use the back/forward buttons as you would normally when browsing the site outside the customizer. The scroll position for each previewed URL is tracked as well, so that when you navigate back/forward the scroll position will be restored, just as happens when browsing the site outside the customizer preview. Restoring the scroll position also works when reloading the customizer, as the position is persisted in a
scroll query parameter: again, this is extremely useful during development.
This plugin complements well the Customize Snapshots plugin which allows you to save your Customizer state in a shapshot/changeset with an associated UUID that also gets added to the browser URL in the Customizer.
For example, if you load the Customizer and then click the “Site Identity” section, the URL will be replaced to add
If you navigate into the nav menus panel, open a menu section, and then expand a nav menu item control, then the URL will have these
autofocus params added:
And while these changes to the
autofocus params are being made in the browser’s URL as the Customizer UI is interacted with, if you navigate to another page in the preview the
url parameter will also be replaced to reflect the new preview URL.
Note that the
url param will be URL-encoded. So a typical Customizer URL would get updated to look like:
The plugin will also persist the scroll position from the frontend to preview frame in the Customizer after clicking the “Customize” link in the frontend admin bar. This ensures you can quickly start editing whatever you were looking at the moment you clicked Customize, and it makes the Customizer load from the frontend in a more seamless way.
Additionally, as you navigate around the Customizer preview, the close link in the Customizer controls pane will keep updating to point to the same URL that you are previewing, along with persisting the scroll position. In this way, whenever you close the Customizer via this link the user experience is that the Customizer sidebar is just removed, similar to as if they clicked the “Hide Controls” link at the bottom of the sidebar. This behavior is only active if the user had clicked the Customize link from the frontend. If they clicked Customize from the admin, then the Close link will remain linking back to the admin page they came from. Note that for responsive themes like Twenty Seventeen, the synced scroll position between the frontend and backend won’t always appear seamless since the Customizer controls panel being expanded causes the element dimensions in the preview to change.
Development of this plugin is done on GitHub. Pull requests welcome. Please see issues reported there before going to the plugin forum.
Contributors & Developers
“Customizer Browser History” is open source software. The following people have contributed to this plugin.Contributors
Translate “Customizer Browser History” into your language.
Interested in development?
Browse the code, check out the SVN repository, or subscribe to the development log by RSS.
- Prevent autofocus params for themes panel and its sections from being included during theme switch. See #22.
- Only remove parent construct autofocus params if child is defined statically; ensures that lazy-loaded children can be autofocused.
- Remove code now irrelevant as of WordPress 4.7.
- Bump minimum WordPress requirement to 4.7.
- Bump tested to 4.9.
Fix reference to
package.json which is not included in build.
Persist scroll position and previewed URL between frontend and customizer preview. See #20.
Prevent dropping non-home initial
url param when loading customizer. See #19.
Fix compatibility with WordPress 4.6. See #17.
changeset_uuid param is added to
customize.php URL if state is dirty OR the changeset post exists. PR #16.
Only include one
autofocus param. If
autofocus[control] is present, skip including
autofocus[section] (since implied). Likewise, if
autofocus[section] is present, also exclude its containing
autofocus[panel] since it is also implied. By only including one
autofocus param the URL bar is less cluttered, but also an issue is fixed where focus may not reliably be added due to apparent inconsistencies in which construct is autofocused first (the control should really be the last to get focus).
Send scroll message to previewer to fix 4.7 scroll position.
Misc cleanup and improve integration with WP 4.7.
Fixed issue whereby an expanded widget control could persist its
autofocus param when another section is expanded.
- Added persistence of
scrollposition when navigating back/forward in the preview and when reloading the customizer.
- Renamed the
customize_previewed_devicequery param to just
- Improved the building of the URL query params to omit any params that are the same as the defaults, so
scroll=0should not be shown, nor should a
urlthat points to the home URL.
- Fixed dropping of value-less query params, e.g.
- Add back/forward browser history for navigation in the Customizer preview. See #2, PR #8.
- Eliminate initial insertion of
customize_previewed_deviceparams when same as default.
Persist the device being previewed (desktop, tablet, mobile) in the URL via a new
customize_previewed_device query param. See #3.
autofocus[control] when there is not a section expanded, such as when a widget is expanded when the sidebar section is collapsed.