Title: Embedding widgets permanently
Last modified: August 19, 2016

---

# Embedding widgets permanently

 *  [czone](https://wordpress.org/support/users/czone/)
 * (@czone)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/embedding-widgets-permanently/)
 * Hello Friends,
    I am new to WordPress and I am trying to built a custom theme,
   if all went well then I want to publish the finished theme for free download.
 * PROBLEM:
    I used few of the widgets to built my theme but the problem is if someone
   want to install my theme then he has to go to widgets section and add those widgets
   to SideBars & even have to install a plugin called “Customizable Search Widget”
   Without configuring the widget section my theme loses its charm and looks ugly.——————————
   I observed that many themes that we install comes with widgets embedded in them
   by default. If anyone can please guide me how to permanently embed widgets then
   it will be og great help.
 * You can see my theme at this link [http://www.mentorarts.com/wordpress/advpress/](http://www.mentorarts.com/wordpress/advpress/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/embedding-widgets-permanently/#post-1847399)
 * This is how I set default widgets:
 *     ```
       <div class="sidebar">
       		<?php
       		if ( !dynamic_sidebar('right-sidebar') ) :
       			if (is_cp_theme_layout('standard,v')) {
       				the_widget('comicpress_calendar_widget');
       			}
       			if (comicpress_themeinfo('disable_comic_frontpage')) {
       				the_widget('comicpress_latest_thumbnail_widget','title=Latest Comic&thumbcat='.comicpress_themeinfo('comiccat'));
       			}
       			the_widget('WP_Widget_Pages');
       			the_widget('WP_Widget_Categories','hierarchical=1&count=1&dropdown=0');
       		endif;
       		?>
       		</div>
       ```
   
 * Basically, if the end user didn’t add widgets to the sidebar it will use those
   defaults i setup, allowing it to not be empty when someone activated the theme.
 * The key thing your looking for is the function called the_widget [http://codex.wordpress.org/Function_Reference/the_widget](http://codex.wordpress.org/Function_Reference/the_widget)
 *  Thread Starter [czone](https://wordpress.org/support/users/czone/)
 * (@czone)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/embedding-widgets-permanently/#post-1847513)
 * Thanks Frumph for helping me, your suggestion solved my prob.
 * **BUT 1 PROBLEM**
 * What if I am using a widget which is not installed in WordPress by default?
 * Since the default widget for search do not allow any styles CSS so I used “Customizable
   Search Widget” for that. How to embed that?
 *  [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/embedding-widgets-permanently/#post-1847515)
 * notice the_widget(‘comicpress_calendar_widget’)
 * that’s not a default widget, it’s one of my theme created ones
 * If you are properly creating your widgets per the 2.8+ widget code, you use I
   believe the registered name for the widget, which in my case I do this:
 *     ```
       class comicpress_calendar_widget extends WP_Widget {
   
       	function comicpress_calendar_widget($skip_widget_init = false) {
       		if (!$skip_widget_init) {
       			$widget_ops = array('classname' => __CLASS__, 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') );
       			$this->WP_Widget(__CLASS__, __('Comic Calendar','comicpress'), $widget_ops);
       		}
       	}
       ```
   
 * the __CLASS__ is the classname itself so when registering the WP_Widget it basically
   keeps the same class name there.
 * Which the classname is then used as the_widget(‘thatnameregistered’)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Embedding widgets permanently’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [Frumph](https://wordpress.org/support/users/frumph/)
 * Last activity: [15 years, 4 months ago](https://wordpress.org/support/topic/embedding-widgets-permanently/#post-1847515)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
