[resolved] Clear the options when a Widget is removed from the sidebar (2 posts)

  1. c.bavota
    Posted 7 years ago #

    I am developing a widget that displays Featured Posts in the sidebar. You can select the number of posts and the category. Whatever category is selected ends up being removed from the main section of the index page so as not to have two of the same posts displayed.

    You can see an example at http://wordpressthemes.tinkerpriestmedia.com/?wptheme=Magazine%20Basic

    The problem I have is that when the Widget is removed from the sidebar, the options still exist and the way it is coded, it checks for those options to arrange everything properly on the main page. Is there a way to clear the options when a Widget is removed or is there a function to check if a Widget has been activated or deactivated?


  2. c.bavota
    Posted 7 years ago #

    I was able to forage around in the WordPress code and found a solution. There is a function called is_active_widget() that allows you to check if a widget has been added to your sidebar in the backend. You can then use a PHP if statement to make something happen only if the widget has been added.

Topic Closed

This topic has been closed to new replies.

About this Topic