Any idea how can I remove or delete Views display programmatically?

I have a Views that has 5 displays and I want to delete one of them. For the sake of avoiding manual intervention I want to do it automatically via code. Is there a way to do that?

  • I had a similar question and found an answer at Sivaji's Drupal Site - sivaji.drupalgardens.com/… Plugging my view name in to lines 5 and 6 worked for me in a hook_update_n(). Commented Apr 2, 2013 at 18:19

1 Answer 1


Here is an example you would put in mymodule.install

* Disable workbench views
function mymodule_update_7001() {
    // an array of views (their view name) I want to disable
    $viewnames = array(

    // grab the array of views that are already disabled
    $views_status = variable_get('views_defaults', array());

    // add our views to be disabled to the list
    foreach ($viewnames as $key => $viewname) {
      $views_status[$viewname] = TRUE;

    // reset the variable with the new list
    variable_set('views_defaults', $views_status);

    // empty cache now
    if (function_exists('views_invalidate_cache')) {
  • this is not an answer. question is about removing of views display
    – milkovsky
    Commented Jul 24, 2014 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.