{"id":8428487,"date":"2016-11-13T00:26:43","date_gmt":"2016-11-13T00:26:43","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/php-why-use-add_action\/"},"modified":"2016-11-13T00:27:24","modified_gmt":"2016-11-13T00:27:24","slug":"php-why-use-add_action","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/php-why-use-add_action\/","title":{"rendered":"PHP: Why use add_action?"},"content":{"rendered":"<p>Hello \ud83d\ude42<br \/>\nI&#8217;ve been using wordpress for 6-7 years, and I&#8217;m starting to get into the &#8220;php side&#8221; of it.<\/p>\n<p>I&#8217;m currently building a simple theme just to learn some basics.<\/p>\n<p>My question is the following:<\/p>\n<p>Why should I use &#8220;add_action&#8221; instead of simply declaring the things I want to do?<br \/>\nFor example, why write: <\/p>\n<pre><code>function arphabet_widgets_init() {\n\n\tregister_sidebar( array(\n\t\t&#039;name&#039;          =&gt; &#039;Home right sidebar&#039;,\n\t\t&#039;id&#039;            =&gt; &#039;home_right_1&#039;,\n\t\t&#039;before_widget&#039; =&gt; &#039;&lt;div&gt;&#039;,\n\t\t&#039;after_widget&#039;  =&gt; &#039;&lt;\/div&gt;&#039;,\n\t\t&#039;before_title&#039;  =&gt; &#039;&lt;h2 class=&quot;rounded&quot;&gt;&#039;,\n\t\t&#039;after_title&#039;   =&gt; &#039;&lt;\/h2&gt;&#039;,\n\t) );\n\n}\nadd_action( &#039;widgets_init&#039;, &#039;arphabet_widgets_init&#039; );<\/code><\/pre>\n<p>instead of just write:<\/p>\n<pre><code>\tregister_sidebar( array(\n\t\t&#039;name&#039;          =&gt; &#039;Home right sidebar&#039;,\n\t\t&#039;id&#039;            =&gt; &#039;home_right_1&#039;,\n\t\t&#039;before_widget&#039; =&gt; &#039;&lt;div&gt;&#039;,\n\t\t&#039;after_widget&#039;  =&gt; &#039;&lt;\/div&gt;&#039;,\n\t\t&#039;before_title&#039;  =&gt; &#039;&lt;h2 class=&quot;rounded&quot;&gt;&#039;,\n\t\t&#039;after_title&#039;   =&gt; &#039;&lt;\/h2&gt;&#039;,\n\t) );\n<\/code><\/pre>\n<p>I think I&#8217;m missing something very important here \ud83d\ude42<\/p>\n<p>Thanks!<br \/>\nBest<\/p>\n","protected":false},"template":"","class_list":["post-8428487","topic","type-topic","status-publish","hentry","topic-tag-add_action"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8428487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8428487\/revisions"}],"predecessor-version":[{"id":8428490,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8428487\/revisions\/8428490"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8428487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}