0

I am using the 2023 theme. I created custom sidebar template parts.

Question: How do I define the custom sidebar template parts to be widget areas that are visible in the Block Widget Editor?

Or should I say, how do I add a widget area to custom template part?

Attempted Solutions: I tried to add the "widget-area" class to each sidebar template part, but no luck.

Any tips?

1 Answer 1

0

You should simply need an appropriate dynamic_sidebar() call in your template.

https://developer.wordpress.org/reference/functions/dynamic_sidebar/

You pass the ID of the sidebar you registered it with using register_sidebar.

https://developer.wordpress.org/reference/functions/register_sidebar/

You may wish to use some logic to see if the sidebar is active first.

$has_sidebar_one = is_active_sidebar( 'first-sidebar-id' ); 

And later in the appropriate area you want to render the sidebar..

<?php if ( $has_sidebar_1 ) : ?> <div class="my_sidebar_element"> <?php dynamic_sidebar( 'first-sidebar-id' ); ?> </div> <?php endif; ?> 

Hope that helps.

4
  • Thanks for the feedback. I don't want to vote you down... but the WP 2023 theme is block based and essentially, nothing you wrote is applicable. Would you like to take a look at the 2023 theme files and adjust your post? Commented Nov 5, 2022 at 7:21
  • Unless I am missing something obvious.. there aren't any php files to edit. Commented Nov 5, 2022 at 7:23
  • I've not worked with any of the block based features yet and have been out of the loop for a while, so i'll have to do a bit of homework and come back to you. Commented Nov 5, 2022 at 7:54
  • I think i'm just going to have to bow out of attempting to answer this question for now, i realise after playing around with it for 30 minutes that i'm not even close to understanding how to use it, nor how you'd even begin to implement something approaching the old widget interface in a block theme. Commented Nov 5, 2022 at 8:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.