WordPress.org

Ready to get started?Download WordPress

Forums

Theme install inactivate widgets (11 posts)

  1. Versipellis
    Member
    Posted 1 year ago #

    What I want to do for a theme I am making is that on install of the theme, move an active widget into inactive.

    I've a search bar at the top of my theme, and therefore do not want it in my sidebar as default. However wordpress puts it there, is there a way to inactivate the search bar from the widget section. I assume it would be something I need to put in my functions.php.

    Is this possible?

    Thanks,

    Versi

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Widgets are stored on a per-theme basis, so your newly installed theme won't have any active widgets to move anywhere.

  3. Versipellis
    Member
    Posted 1 year ago #

    When I started making this theme, I took a copy of twenty eleven as I usually do and started editing.

    Three widgets, search, pages and meta, were automatically put in.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Try looking in sidebar.php. That's the default sidebar content - not added widgets.

  5. Versipellis
    Member
    Posted 1 year ago #

    Well I've looked there, which just says it loads 'sidebar-1' if Dynamic.

    Sidebar 1 in my functions.php is as follows:

    register_sidebar( array(
    		'name' => __( 'Sidebar', 'twentyeleven' ),
    		'id' => 'sidebar-1',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => "</aside>",
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );

    As far as I can see that is not automatically putting in search, pages and meta widgets into the back end?

    Also you stated:

    Widgets are stored on a per-theme basis, so your newly installed theme won't have any active widgets to move anywhere.

    But I always find that installing wordpress puts in those same three widgets with twenty eleven, then if I change theme they always stay no matter how many themes I test with.

    I know code to completely unregister a widget, but thats not what I want.

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    Look again.

    <?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
    
    	<aside id="archives" class="widget">
    		<h3 class="widget-title"><?php _e( 'Archives', 'twentyeleven' ); ?></h3>
    		<ul>
    			<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
    		</ul>
    	</aside>
    
    	<aside id="meta" class="widget">
    		<h3 class="widget-title"><?php _e( 'Meta', 'twentyeleven' ); ?></h3>
    		<ul>
    			<?php wp_register(); ?>
    			<li><?php wp_loginout(); ?></li>
    			<?php wp_meta(); ?>
    		</ul>
    	</aside>
    
    <?php endif; // end sidebar widget area ?>
  7. Versipellis
    Member
    Posted 1 year ago #

    <?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>

    Thats stating, if Does Not Have Dynamic Sidebar 'sidebar-1' Display Following.

    Thats what shows if you Do Not have any widgets in your sidebar in the backend.

    Removing that will not do anything as, when the theme installs, there are already widgets active...

    I want to force wordpress to inactivate all active widgets on install of my theme.

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    You theme will NOT have any active widgets. Widgets are stored on a PER THEME basis. Therefore, if this is a fresh install of a completely new theme, it will not have any widgets. This is even the case with child themes.

  9. Versipellis
    Member
    Posted 1 year ago #

    Every time I install wordpress, it puts the twenty eleven theme in. With those widgets.

    If I change theme, the widgets stay. This has happened on every single wordpress I have worked with, and I have several installs locally and several live websites.

    Plus I cannot guarantee a user does not already have widgets activated, I cannot guarantee that they are using a fresh install.

    Every new theme I install has the same widgets in that are put in prior to install. On any wordpress I have from 3.0 to the latest.

  10. esmi
    Forum Moderator
    Posted 1 year ago #

    it puts the twenty eleven theme in. With those widgets.

    No - not widgets. Default sidebar content. This content is then removed if/when you add real widgets via Appearance -> Widgets. It is these "real" widgets that are then saved, in the database, but only for Twenty Eleven and no other theme.

    Plus I cannot guarantee a user does not already have widgets activated,

    It doesn't matter. If they switch to another theme, any previously active widgets will be automatically moved to Inactive by WordPress itself. They will not be activated again unless:

    1. The user adds them back manually
    or

    2. The user switches back to the old theme.

  11. Versipellis
    Member
    Posted 1 year ago #

    Well how come when I install wordpress I automatically get these and more WIDGETS in my sidebar, and I have to go into the dashboard > appearance > widgets and they are sat there in the first of 5 sidebars. So I don't see how you can say it is the default sidebar content when I have installed a vanilla wordpress today and there are plenty of WIDGETS in my BACKEND sidebar options.

    So what you've said is completely wrong, if you change theme those WIDGETS stay I have tested this already today, and the WIDGETS are there on install of wordpress and the twenty eleven them. Tested today.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.