{"id":223,"date":"2012-04-13T14:41:41","date_gmt":"2012-04-13T19:41:41","guid":{"rendered":"http:\/\/www.marcblase.com\/blog\/?p=223"},"modified":"2012-04-13T14:48:56","modified_gmt":"2012-04-13T19:48:56","slug":"remove-widgets-from-wp-sidebar","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2012\/04\/remove-widgets-from-wp-sidebar\/","title":{"rendered":"Remove Widget from WP Sidebar"},"content":{"rendered":"<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nadd_filter('sidebars_widgets', 'hidemywidget');\r\nfunction hidemywidget($all_widgets) {\r\n    \/\/ Uncomment to get access to the identifiers we are trying to target\r\n    \/\/echo &quot;&lt;pre&gt;&quot;;\r\n    \/\/print_r($all_widgets);\r\n    \/\/echo &quot;&lt;\/pre&gt;&quot;;\r\n    \/\/comment the following out and see what happens!\r\n    \/\/return $all_widgets;\r\n    \/\/this should run on the homepage \/ frontpage only! you can use more conditions here\r\n    if( is_front_page() || is_page() ){\r\n\t\t\/\/ match to your registered sidebar widget!!!\r\n        foreach ($all_widgets&#x5B;'sidebar-1'] as $i =&gt; $inst){\r\n            \/\/check if the id for the widget to extract exists.\r\n            $pos = strpos($inst, 'categories');\r\n \r\n            if($pos !== false)\r\n            {\r\n                \/\/remove the archives widget by unsetting it's id\r\n                unset($all_widgets&#x5B;'sidebar-1']&#x5B;$i]);\r\n            }\r\n        }\r\n    }\r\n\/\/comment the following out and see what happens!\r\nreturn $all_widgets;\r\n}\r\n<\/pre>\n<p>To do: Target an array of widgets to exclude. Rewrite function to pass vars as arguments of function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>add_filter(&#8216;sidebars_widgets&#8217;, &#8216;hidemywidget&#8217;); function hidemywidget($all_widgets) { \/\/ Uncomment to get access to the identifiers we are trying to target \/\/echo &quot;&lt;pre&gt;&quot;; \/\/print_r($all_widgets); \/\/echo &quot;&lt;\/pre&gt;&quot;; \/\/comment the following out and see what happens! \/\/return $all_widgets; \/\/this should run on the homepage \/ frontpage only! you can use more conditions here if( is_front_page() || is_page() ){ \/\/ match [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-coding","category-discoveries"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":5,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}