You’re quite off with your code. That’s not how widgets are stored (at least not since 2.8), plus you’re trying to inject arrays into strings!
Setting default widgets (at least in the admin) seems a complex & messy task. I would much rather opt for default widgets in the display logic instead.
<?php if ( ! dynamic_sidebar( 'primary-sidebar' ) ) : ?>
<div class="widget">
My default widgets!
</div>
<?php endif ?>
The content within the if
statement will print if no widgets have been configured, which will be the case on initial theme activation.
Related Posts:
- Create new sidebars trough admin post/page metabox
- Custom widgets in theme option page
- Can I create my own “Recent Posts” widget or customize the existing one?
- How to store widget fields data as an array?
- WordPress API Menu/Submenu Order
- Adding a div to wrap widget content after the widget title
- What is the difference between wp_register_sidebar_widget and register_widget?
- How to enqueue script if widget is displayed on page?
- What are the advantages and disadvantages of Option Tree over the Customization API?
- How do I add settings to the Background Options Page?
- How To Add New Option Types To Option Tree?
- Is it possible ( or advisable) to allow open access to the new theme customizer for potential clients?
- What WP folder can I use to write files to?
- WordPress Settings API error
- Call dynamic_sidebar but include/exclude named widgets?
- Add a dropdown to theme customizer
- Understanding wp_add_inline_style
- Should I use set_transient or update_option?
- Add a new checkbox in theme options
- HowTo: Add Class to Sidebar Widget List-Items
- How to add Color Picker in Theme Options for the following?
- Setting multiple default background images?
- Best practice way to implement custom sections into a WordPress theme
- register_sidebar ignores ‘id’ and ‘class’
- How wp_cache is supposed to work, and does it help with performance?
- Best practice (forward compatibility) for theme options
- How to set the default value of a option in a theme?
- How to determine the current widget’s parent container (sidebar widget id)
- Adding widgets programatically: how to avoid collisions?
- Add class to before_widget for all widgets with a dropdown and a counter
- Where is default wp_head() implemented?
- Add a preview to a WordPress Control Panel
- WordPress settings API error when checkbox unchecked
- Enabling Widgets By Default in Custom Theme Development
- How to deploy a new theme/theme options from staging to production site
- WordPress Customizer Typography: How to load just the unique Google Fonts?
- use add_action(‘wp_head’) in a widget for generating dynamic CSS styles
- Registering Sidebars and Sidebar Widgets. Sidebar Widgets Not Displaying
- File included into functions.php via require_once() won’t echo?
- What is the best way to export and import theme options?
- Adding inline styles from a widget
- modify a output of a widget
- Context aware widgets. My work in progress
- How to determine which sidebar the widget has been added to, via widget admin?
- How can I add an incremental class identifier to my sidebar widgets?
- How to Modify a Widgets UL and/or LI Classes
- Should use widgets in this case?
- Enabling Default Widgets in a Custom Theme
- esc_url not working within add_settings_field callback
- how to create theme based widget that can be drop in sider bar or footer
- How to remove menus section from WordPress theme customizer
- WordPress Errors in generated by theme check plugin [closed]
- How to add a text widget during theme activation
- WordPress Theme customisation CSS
- I updated my own theme’s code and css
- Theme option page doesn’t save options
- How to customize the colors within a stylesheet using a WordPress setting
- Display problems in admin dashboard when creating a new theme from scratch
- Create settings field on button click
- how can I re-utilize and class on a child theme
- how to call options on front end and add logo
- how to create export / import theme options in wordpress without plugin
- Customizer_register theme options not saving
- How can I include the js and css file of my custom theme dynamically in header.php
- Undefined index: custom_sidebars
- Using Customizer value in an external PHP file inside a theme
- Best strategy for providing theme options using customizer
- WordPress Footer Widget Processing
- Custom widget not appearing on front end
- What’s the policy for building a theme that doesn’t support widgets/menus?
- “No Data Received” error in Chrome every time i try to update the theme functions file
- Creating a Playlist of Widgets
- How to display only some widgets of a sidebar?
- trying to figure out how to use more that one image upload in the same section in theme customizer
- Default calendar widget not showing up
- Theme Options Doesn’t Work On WP Multisite
- WordPress two sidebar layout or theme
- Menu item not created on theme activation
- Theme automatically inserting “more” tag on every post
- Theme Option’s Save Button is not working
- WordPress widgets manager option for emulating theme layout
- Adding custom widgets to theme sidebar on activation
- wp_deregister_script was called incorrectly
- The content not wrapped in paragraph tags with get_page_by_title()
- Undefined index: debuging error for theme option template snippet
- Option to show/hide widget depending on is_home?
- How to Disable Color Options?
- Import/Export WordPress demo
- Turning WordPress Into full-featured website?
- Theme with Isoptope after activation in new install not working well [closed]
- How to make admin theme option with image slide show?
- Replacing static code in a template file with a sidebar and widgets?
- Theme.json: creating different sections of the color palette
- Is it ok if I use this tag?
- How to show associated fields if checkbox is checked in customize widget screen using wp_customize?
- Remove nonindex meta tag
- TItle In Latest Post is not using H1 Tag [closed]
- Export WordPress theme with modifications for other site
- WordPress 6.4.2 – can’t load editor style css using ‘after_setup_theme’ or ‘admin_init’ actions
- how can i modify the default wordpress sidebar