Eric B
Eric B

Reputation: 85

Where should the code for a WordPress hook function be located?

I am new to Wordpress/WooCommerce and PHP, although I have experience in other web platforms and languages.

I have read numerous articles about adding code to WooCommerce and where to place your code, and of course there are many different answers.

It seems that the most common answers are to place you code in the child themes functions file, while others say that you should create your own plug-in and place the code there.

I am leaning toward my own plug-in so that if the theme is updated or changed, the code wont be lost.

Can a hook (created by calling add_action()) and it's associated function be created in my own plug-in?

Upvotes: 0

Views: 72

Answers (1)

zipkundan
zipkundan

Reputation: 1774

Yes, you can override actions/filters of wordpress or any other plugin via your plugin.

Apart from that, if you use child theme (inheriting parent theme) you do not loose the customization you have made via child theme even when the parent theme is updated.

If the theme is changed all together, there is possibility that your customization may behave different as the actions/hooks can be used differently in themes.

Hope this helps.

Upvotes: 1

Related Questions