what is option_name on database that store the information of current initiate widget in frontend sidebar ?
Leave a Reply
You must be logged in to post a comment.
what is option_name on database that store the information of current initiate widget in frontend sidebar ?
You must be logged in to post a comment.
Sidebar widgets are stored in multiple places in the database. To be perfectly honest, I think it would be next to impossible to have your theme create a pre-populated, widgetized sidebar when it first installs.
However, there is still a way to set up a default widget display for when you install a theme the first time. If you take a look at the default TwentyTen theme, you’ll see that it defines a list of “default” widgets that will be loaded if the user doesn’t have a dynamic sidebar:
This code block hard-codes a search widget, an archives widget, and a meta widget. Pretty basic, but it means new blogs will always show something useful in the sidebar even if the owner hasn’t had the chance to customize the site just yet.
If you’re shooting for creating “a list of widgets that is automatically installed when a theme registers for the first time” then this is the safest, and friendliest way to do it.
Solved.
What EAmann said is right. The problem is in the configuration of the widget system in WordPress. For every multi-instance widget such as text, The information is stored in a different option name where the value of every widget store in a serialized manner.
The trick is about how we store the serialized text widget’s information that sometimes has special chars. We must use heredoc. The use of heredoc is to avoid the situation when a string must contain [‘] and [“], because both can not be use on one line together.
Now we can store them in the database:
PS: If we store multi-instance widgets then we should remember that the widgets have their own configuration. For example, text widget is stored in ‘widget_text’
PS: Read how to use heredoc in PHP.