Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget Screen Documentation for Fallbacks and Default widgets #26298

Open
DaisyOlsen opened this issue Oct 19, 2020 · 4 comments
Open

Widget Screen Documentation for Fallbacks and Default widgets #26298

DaisyOlsen opened this issue Oct 19, 2020 · 4 comments
Labels
[Feature] Widgets Screen The block-based screen that replaced widgets.php. [Type] Developer Documentation Documentation for developers

Comments

@DaisyOlsen
Copy link
Contributor

Feedback from WPTavern:
One less-obvious piece of documentation should center on how to handle fallbacks or default widgets. Traditionally, themes that needed to show a default set of widgets would check if the sidebar has widgets and fall back to using the_widget() to output one or more defaults. While theme authors can still do that, we should start to transition them across the board to the block system.

@DaisyOlsen DaisyOlsen added [Feature] Widgets Screen The block-based screen that replaced widgets.php. [Type] Developer Documentation Documentation for developers labels Oct 19, 2020
@noisysocks
Copy link
Member

Here is where this pattern is documented:

https://developer.wordpress.org/themes/basics/conditional-tags/#variable-sidebar-content

Something like this should work as a block-based alternative:

if ( is_active_sidebar( 'my_sidebar' ) ) {
	dynamic_sidebar( 'my_sidebar' );
} else {
	echo do_blocks( '<!-- wp:paragraph --><p>Fallback block content goes here.</p><!-- /wp:paragraph -->' );
}

@ryanwelcher
Copy link
Contributor

@DaisyOlsen is this still actionable?

@DaisyOlsen
Copy link
Contributor Author

Maybe ask @justintadlock since it was pulled directly from his feedback.

@justintadlock
Copy link
Contributor

This ticket should be moved here: https://github.com/WordPress/Documentation-Issue-Tracker/issues

The code from @noisysocks looks like a good solution, but it should be shown here in the current handbook: https://developer.wordpress.org/themes/functionality/sidebars/#display-default-widgets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Widgets Screen The block-based screen that replaced widgets.php. [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

No branches or pull requests

4 participants