I have a small widget which gets some information from other websites. Now, at times it is possible that these other websites are not available.

Is it possible to disable or hide a widget automatically (through the WP_Widget class, i.e. in my code that extends it) whenever I detect an error? I don't wish to disable it permanently, I just don't want to have failures that break my page and at the same time I don't want to display things like 'Error retrieving data' or whatever... I just want to hide the widget all along.

  • 1
    Well, you could have a IF statement checking what kind of content the widget returns, so that you can choose to display the results or not. But how can anyone here help you if there's no code to look at? You will need to be more specific. Did you write the code for the widget? Can you provide us with code for the widget? Code for the template where the widget is? – gdaniel Mar 12 '14 at 21:44
  • Not sure what you mean. I have no difficulty with my code, its whether it is possible to tell wordpress 'don't show this widget completely' what I am asking. By don't show I mean not even the title or the background box or anything. Of course I can have an If statement or a try - catch to handle the exception, its hiding the widget altogether if it happens I am asking about. Maybe there is a flag in WP_Widget or some way. I don't know what I should give you because its just my code which is irrelevant for what I am asking. Just assume I have an error code from my function call... – jbx Mar 13 '14 at 0:51
  • Good luck then. – gdaniel Mar 13 '14 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.