wordpress - Registering sidebar with or without hook -


i'm little bit confused on it. when registering sidebar in function file of wordpress, use register_sidebar() function , pass arguments in it.

without using action hook, sidebar works fine. however, in codex i've seen action hook named 'widget_init' used register sidebar. so, confusion standard approach register sidebar, or without action hook ?

i found this interesting piece on registering sidebars says

bad sidebar code

there common things see changed within themes. not of these things technically incorrect, can present unintended consequences or needless bits of code.

problem #1: randomly dropping code functions.php

if you’re theme developer, should familiar wordpress’ built-in hooks. not should familiar them, should using them.

the biggest issue see sidebar code being dropped functions.php. should create sidebar registration function , hook widgets_init. can see example of in “registering dynamic sidebar” section above.

the reason important child themes (and plugins) can know when sidebar registered. gives child themes opportunity unregister sidebar if needed. plus, not doing way plain sloppy.


as sidenote this: should never drop code functions.php. use hooks wordpress provides execute functions when should executed in wordpress flow.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -