{"id":41,"date":"2023-11-29T09:12:43","date_gmt":"2023-11-29T09:12:43","guid":{"rendered":"http:\/\/localhost:9090\/?p=41"},"modified":"2024-06-23T03:48:17","modified_gmt":"2024-06-23T03:48:17","slug":"wordpress-tip-101","status":"publish","type":"post","link":"http:\/\/localhost:9090\/wordpress-tip-101\/","title":{"rendered":"WordPress Tip 101"},"content":{"rendered":"\n
If the function from the parent theme isn\u2019t pluggable, you can still prevent it from running. Imagine your parent theme has a function called Here\u2019s what the parent theme function might look like:<\/p>\n\n\n\n To unhook it, you\u2019d code this in your child theme:<\/p>\n\n\n\n Note that you hook your second function to the wp_head hook which is run at the top of each page, and that you have to include the same value for the priority parameter as in the original function. If the original parent_function()<\/code>, which is hooked to the
init<\/code> hook with a priority of
20<\/code>. You want to prevent it from running so you can replace it with a function of your own.<\/p>\n\n\n\n
function<\/span> parent_function<\/span>(<\/span>)<\/span> {<\/span>\n \/\/contents of function here<\/span>\n}<\/span>\nadd_action<\/span>(<\/span> \u2018init\u2019,<\/span> \u2018parent_function\u2019,<\/span> 20<\/span> )<\/span>;<\/span><\/code><\/pre>\n\n\n\n
function<\/span> remove_parent_function<\/span>(<\/span>)<\/span> {<\/span>\n remove_action<\/span>(<\/span> \u2018init\u2019,<\/span> \u2018parent_function\u2019,<\/span> 20<\/span> )<\/span>;<\/span>\n}<\/span>\nadd_action<\/span>(<\/span> \u2018wp_head\u2019,<\/span> \u2018remove_parent_function\u2019 )<\/span>;<\/span><\/code><\/pre>\n\n\n\n
add_action()<\/code> function didn\u2019t have a priority, you can omit that from your child theme\u2019s
remove_action()<\/code> function.<\/p>\n\n\n\n