You need to wrap this in a function then add it to the widgets_init action. Also the register sidebar function does not have $arguments for sort_column or sort_order. I would also change the id to 'sidebar-'.$page->ID
add_action( 'widgets_init', 'prefix_register_sidebars' );
function prefix_register_sidebars() {
foreach($pages as $page){
register_sidebar( array(
'name'=>$page->post_title,
'id'=> 'sidebar-'.$page->ID,
'before_widget' => '<div id="%1$s" class="'.$page->slug.' widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
)
);
}
Related Posts:
- Get sidebar parameters (before_widget, before_title, etc.) from within a widget
- Add div class to only one widget
- How to avoid widgets added to sidebar on theme activation?
- More flexible sidebar and widget management
- WordPress widget new instance creates content duplicates
- duplicate sidebar
- Removing custom widget area WordPress 4.4 [closed]
- Insert Widget option into mark-up with register_sidebar
- Cannot save widgets in custom sidebars
- Can’t see widget areas in my customizer
- Widgets not activated alert after using get_sidebar()
- Can you target a widget_class in a register_sidebar?
- Copy Widget Settings because of changed IDs
- Add class to on sidebar widget
- activate custom sidebar widgets
- How to create sidebar from “scratch”?
- How to get sidebar widgets in leftsidebar template
- $before/after_widget/title not displaying anything
- Unique widget id in sidebar
- Programmatically add widgets to sidebars
- Loading scripts only if a particular shortcode or widget is present
- Give Editor Access To Sidebar
- Where is the content of widgets stored in mysql table
- Get number of widgets in sidebar
- Text Widget creates a
- Add the sidebar/widget editor to the post edit screen?
- Show Woocommerce minicart widget in checkout page sidebar? And, how to make this update secure by overriding widget?
- HowTo: Add Class to Sidebar Widget List-Items
- Different widgets on different page templates?
- How to add author details in the post sidebar?
- Determining a Widget Instance and Sidebar Location?
- Randomize widgets displayed in my sidebar [duplicate]
- What is the use case for the “Class” parameter in register_sidebar?
- Add a select box to all widgets
- Hooking Into Widget Output Loop
- Display sidebar that created in functions.php
- Create variable from widget instance
- Save/update widget outside admin panel [closed]
- WordPress: Apply filter/hook to a particular sidebar widgets?
- Why use dynamic_sidebar() conditionally?
- wordpress widget textbox in the sidebar
- WordPress Widget multiple use
- Contact Form in sidebar [closed]
- dynamic_sidebar() returns false in admin section
- How to check if searchform.php is being included as widget?
- How to get sidebar’s content inside admin-ajax?
- Full width layout for custom post type pages
- How to “pair” two widgets side by side in one sidebar [closed]
- Adding custom html and standard widgets to sidebar
- Dynamic Sidebars On Multiple Subpages
- How to add new sidebar widget area to child theme?
- Check which registered sidebar a widget is added to
- Disable widgets on specific posts
- Display the id list of active widgets of same sidebar?
- How to remove a widget from the sidebar on specific page?
- Add individual tag to widget title in sidebar
- Toggle option in sidebar widgets
- How to show different widgets on different pages in a user friendly way
- Default widgets assignment – isn’t working
- Programmatically add widgets to sidebars
- Programmatically add widgets to sidebars
- How to call widget by widget’s id?
- wp_get_attachment_image() not displaying post images even though wp_get_attachment_url() echo correct urls
- Show a widget as a sidebar fallback
- register_sidebar fails when using a include within functions.php
- How to pass a special CSS class into widget li
- Add a specific css to a widget
- what is the best way to add things to a side bar
- Is there a simple way to have a new sidebar for each page?
- how to add the same Widget twice to a sidebar?
- Save button is not working on custom widget
- My widget not printing before_widgets and after widgets
- Register_Sidebar overwriting itself and doesn’t exist in global $wp_registered_sidebars;
- Multiple rows of footer widget areas
- Check if widget is inside sidebar with PHP
- New Widget are not showing
- How do I exclude portrait pictures from the nextgen gallery sidebar widget?
- Upgraded to 3.3, My Widgets Disappeared
- How to use register_sidebar’s ‘before_widget’ unique id generator into its other parameters like ‘before_title’?
- Need to delete the sidebar widget area and have the page a full page rather than just have a blank widget area
- After adding widget the style is messing up
- Siderbar implementation with collapsible bootstrap cards
- Before_widget won’t show up
- Reposition the widget sidebar in Appearance->Widgets
- Handling dozens of sidebars
- Does current page contain widget or sidebar
- widgets_init actions not fired from functions.php’s child theme
- Active Sidebar Conditional Question?
- Target logic based on Widget / Sidebar Name
- Paginate recent posts widget
- Widget Areas Still Appearing in WP ADMIN When They Shouldn’t
- Inkness theme sidebar
- register_sidebar() will not wrap an element properly
- Automatically hide Widgets that would lengthen page
- How to exclude a widget from showing up on a page?
- How to hide sidebar widgets in all pages except Hompage?
- Keeping shortcode-generated widget and theme element in one line [closed]
- is it possible to create custom widgets page in admin?
- How to tell if a dynamic sidebar is being displayed on page?
- Add custom settings to widget areas