Posted on Leave a comment

Add Action Hack to Register Sidebars, Menus and Widgets

Hybrid Child Menu Order

I have been editing, WordPress.com themes for more than 5 years not, and I have been doing these just by learning from books but mostly learning by doing. Today, 29 June 2017 I found myself confused why some of my extended/ additional widgets appear before Main Sidebar/ Widgets and why others appear after main sidebar/ widgets

/* Register sidebars. */ add_action( 'init', 'hybrid_theme_register_sidebars', 11 );

Hybrid Child Theme Sidebars / Widgets after adding action hooks
Hybrid Child Theme Sidebars / Widgets after adding action hooks

For example in my Hybrid Theme we have Primary, Secondary and Subsidiary Sidebars, plus Before Container, Before Content, After Singular, After Content and After Content Widgets. These are the “Main Sidebar/ Widgets” that come with the Hybrid Theme. Now, when I want to add more widgets/ sidebars to my Child Theme that I call “Hybrid Child Theme”. I added Home Sidebar, Archive Sidebar, Home Top Sidebar, Home Middle Sidebar and Home Bottom Sidebar, then when I click on Admin “Apperaance/Widgets”, it will appear like below:

Hybrid Theme Child Widgets before Changing the Order
Hybrid Theme Child Widgets before Changing the Order

After adding Number “11” to the add_action in functions.php, then the order of the additional widgets and sidebars follow after primary widgets and sidebars, as seen in the following image

Exactly the same thing happens with Menus, the primary and secondary menus appear after the additional menus in Child Theme if we register the additional menus without adding Number “11” or “12” or whatever it is after add_action Hooks. The following image shows the order of menus before adding the number

Hybrid Child Menu Order
Hybrid Child Menu Order Before Adding No. 11

Now after adding number “11” in this cafe, like this

then the following is what happens on the Admin Menu section

Hybrid Child Menu Order
Hybrid Child Menu Order after Adding No. 12

/* Register additional menus for HybridChild theme. */ /* Register additional menus for HybridChild theme. */ add_action( 'init', 'hybrid_child_register_menus', 11 );

For me this is a good revelation, from learning by doing. I know many people in the world out there have known this for long time, but for me at least, this is a useful experience to write and post it here.