{"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

Unhooking a Function from the Parent Theme<\/a><\/h4>\n\n\n\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 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

Here\u2019s what the parent theme function might look like:<\/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

To unhook it, you\u2019d code this in your child theme:<\/p>\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

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 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

Note: If the original function was hooked to a filter hook instead of an action hook, you would use remove_filter()<\/code> in the same way.<\/em><\/p>\n\n\n\n

Augmenting a Function With Another Function<\/a><\/h4>\n\n\n\n

Instead of overriding or removing a function, sometimes you might want to add to it instead. In this case, you\u2019d write a new function with a different name, and attach it to the same hook.<\/p>\n\n\n\n

Let\u2019s imagine there is an action hook for the footer in your parent theme called parent_footer<\/code>. Any function you attach to that hook will run in the place where the hook is situated.<\/p>\n\n\n\n

In the parent theme, there\u2019s already a function called parent_footer_content()<\/code> that populates the footer. But what if you wanted to add some extra code to it?<\/p>\n\n\n\n

Here\u2019s what the parent_footer_content()<\/code> function might look like in the parent theme:<\/p>\n\n\n\n

function<\/span> parent_footer_content<\/span>(<\/span>)<\/span> {<\/span>\n \/\/ content of function here<\/span>\n}<\/span>\nadd_action<\/span>(<\/span> \u2018parent_footer\u2019,<\/span> \u2018parent_footer_content\u2019 )<\/span>;<\/span><\/code><\/pre>\n\n\n\n

Now if you wanted to add additional content after that, you would create a function in your child theme, hooked to the same action hook, with a priority that meant it run after the first function. As the priority isn\u2019t set for the parent theme\u2019s function, it defaults to 10. So you need to use a higher number so it fires after that.<\/p>\n\n\n\n

function<\/span> child_footer_extra_content<\/span>(<\/span>)<\/span> {<\/span>\n \/\/ contents of function here<\/span>\n}<\/span>\nadd_action<\/span>(<\/span> \u2018parent_footer\u2019,<\/span> \u2018child_footer_extra_content\u2019,<\/span> 20<\/span> )<\/span>;<\/span><\/code><\/pre>\n\n\n\n

This would add the code from your child theme\u2019s function after the code from your parent theme\u2019s function.<\/p>\n\n\n\n

An Example<\/h2>\n\n\n\n

This is a snippet I used to get rid of the footer in the Attitude theme<\/p>\n\n\n\n

\nadd_action( 'wp_head', 'remove_attitude_footer' );\n\nfunction remove_attitude_footer() {\n remove_action( 'attitude_footer', 'attitude_footer_info', 30 );\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Unhooking a Function from the Parent Theme 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 parent_function(), which is hooked to the init hook with… <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"yoast_head":"\nWordPress Tip 101 - Ray Sayz<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/localhost:9090\/wordpress-tip-101\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress Tip 101 - Ray Sayz\" \/>\n<meta property=\"og:description\" content=\"Unhooking a Function from the Parent Theme 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 parent_function(), which is hooked to the init hook with…\" \/>\n<meta property=\"og:url\" content=\"http:\/\/localhost:9090\/wordpress-tip-101\/\" \/>\n<meta property=\"og:site_name\" content=\"Ray Sayz\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-29T09:12:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-23T03:48:17+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/localhost:9090\/wp-content\/uploads\/2024\/06\/DSCF0270_web_best-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1710\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"raysayz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"raysayz\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t \"@context\": \"https:\/\/schema.org\",\n\t \"@graph\": [\n\t {\n\t \"@type\": \"Article\",\n\t \"@id\": \"http:\/\/localhost:9090\/wordpress-tip-101\/#article\",\n\t \"isPartOf\": {\n\t \"@id\": \"http:\/\/localhost:9090\/wordpress-tip-101\/\"\n\t },\n\t \"author\": {\n\t \"name\": \"raysayz\",\n\t \"@id\": \"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9\"\n\t },\n\t \"headline\": \"WordPress Tip 101\",\n\t \"datePublished\": \"2023-11-29T09:12:43+00:00\",\n\t \"dateModified\": \"2024-06-23T03:48:17+00:00\",\n\t \"mainEntityOfPage\": {\n\t \"@id\": \"http:\/\/localhost:9090\/wordpress-tip-101\/\"\n\t },\n\t \"wordCount\": 379,\n\t \"publisher\": {\n\t \"@id\": \"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9\"\n\t },\n\t \"articleSection\": [\n\t \"Linux\"\n\t ],\n\t \"inLanguage\": \"en-US\"\n\t },\n\t {\n\t \"@type\": \"WebPage\",\n\t \"@id\": \"http:\/\/localhost:9090\/wordpress-tip-101\/\",\n\t \"url\": \"http:\/\/localhost:9090\/wordpress-tip-101\/\",\n\t \"name\": \"WordPress Tip 101 - Ray Sayz\",\n\t \"isPartOf\": {\n\t \"@id\": \"http:\/\/localhost:9090\/#website\"\n\t },\n\t \"datePublished\": \"2023-11-29T09:12:43+00:00\",\n\t \"dateModified\": \"2024-06-23T03:48:17+00:00\",\n\t \"breadcrumb\": {\n\t \"@id\": \"http:\/\/localhost:9090\/wordpress-tip-101\/#breadcrumb\"\n\t },\n\t \"inLanguage\": \"en-US\",\n\t \"potentialAction\": [\n\t {\n\t \"@type\": \"ReadAction\",\n\t \"target\": [\n\t \"http:\/\/localhost:9090\/wordpress-tip-101\/\"\n\t ]\n\t }\n\t ]\n\t },\n\t {\n\t \"@type\": \"BreadcrumbList\",\n\t \"@id\": \"http:\/\/localhost:9090\/wordpress-tip-101\/#breadcrumb\",\n\t \"itemListElement\": [\n\t {\n\t \"@type\": \"ListItem\",\n\t \"position\": 1,\n\t \"name\": \"Home\",\n\t \"item\": \"http:\/\/localhost:9090\/\"\n\t },\n\t {\n\t \"@type\": \"ListItem\",\n\t \"position\": 2,\n\t \"name\": \"WordPress Tip 101\"\n\t }\n\t ]\n\t },\n\t {\n\t \"@type\": \"WebSite\",\n\t \"@id\": \"http:\/\/localhost:9090\/#website\",\n\t \"url\": \"http:\/\/localhost:9090\/\",\n\t \"name\": \"Ray Sayz\",\n\t \"description\": \"Nowhere, everywhere ... now\",\n\t \"publisher\": {\n\t \"@id\": \"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9\"\n\t },\n\t \"potentialAction\": [\n\t {\n\t \"@type\": \"SearchAction\",\n\t \"target\": {\n\t \"@type\": \"EntryPoint\",\n\t \"urlTemplate\": \"http:\/\/localhost:9090\/?s={search_term_string}\"\n\t },\n\t \"query-input\": \"required name=search_term_string\"\n\t }\n\t ],\n\t \"inLanguage\": \"en-US\"\n\t },\n\t {\n\t \"@type\": [\n\t \"Person\",\n\t \"Organization\"\n\t ],\n\t \"@id\": \"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9\",\n\t \"name\": \"raysayz\",\n\t \"image\": {\n\t \"@type\": \"ImageObject\",\n\t \"inLanguage\": \"en-US\",\n\t \"@id\": \"http:\/\/localhost:9090\/#\/schema\/person\/image\/\",\n\t \"url\": \"http:\/\/localhost:9090\/wp-content\/uploads\/2024\/06\/raysayz_upscaled.png\",\n\t \"contentUrl\": \"http:\/\/localhost:9090\/wp-content\/uploads\/2024\/06\/raysayz_upscaled.png\",\n\t \"width\": 800,\n\t \"height\": 800,\n\t \"caption\": \"raysayz\"\n\t },\n\t \"logo\": {\n\t \"@id\": \"http:\/\/localhost:9090\/#\/schema\/person\/image\/\"\n\t },\n\t \"sameAs\": [\n\t \"http:\/\/localhost:9090\"\n\t ],\n\t \"url\": \"http:\/\/localhost:9090\/author\/raysayz\/\"\n\t }\n\t ]\n\t}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress Tip 101 - Ray Sayz","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/localhost:9090\/wordpress-tip-101\/","og_locale":"en_US","og_type":"article","og_title":"WordPress Tip 101 - Ray Sayz","og_description":"Unhooking a Function from the Parent Theme 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 parent_function(), which is hooked to the init hook with…","og_url":"http:\/\/localhost:9090\/wordpress-tip-101\/","og_site_name":"Ray Sayz","article_published_time":"2023-11-29T09:12:43+00:00","article_modified_time":"2024-06-23T03:48:17+00:00","og_image":[{"width":2560,"height":1710,"url":"http:\/\/localhost:9090\/wp-content\/uploads\/2024\/06\/DSCF0270_web_best-scaled.jpg","type":"image\/jpeg"}],"author":"raysayz","twitter_card":"summary_large_image","twitter_misc":{"Written by":"raysayz","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/localhost:9090\/wordpress-tip-101\/#article","isPartOf":{"@id":"http:\/\/localhost:9090\/wordpress-tip-101\/"},"author":{"name":"raysayz","@id":"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9"},"headline":"WordPress Tip 101","datePublished":"2023-11-29T09:12:43+00:00","dateModified":"2024-06-23T03:48:17+00:00","mainEntityOfPage":{"@id":"http:\/\/localhost:9090\/wordpress-tip-101\/"},"wordCount":379,"publisher":{"@id":"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9"},"articleSection":["Linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/localhost:9090\/wordpress-tip-101\/","url":"http:\/\/localhost:9090\/wordpress-tip-101\/","name":"WordPress Tip 101 - Ray Sayz","isPartOf":{"@id":"http:\/\/localhost:9090\/#website"},"datePublished":"2023-11-29T09:12:43+00:00","dateModified":"2024-06-23T03:48:17+00:00","breadcrumb":{"@id":"http:\/\/localhost:9090\/wordpress-tip-101\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/localhost:9090\/wordpress-tip-101\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/localhost:9090\/wordpress-tip-101\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/localhost:9090\/"},{"@type":"ListItem","position":2,"name":"WordPress Tip 101"}]},{"@type":"WebSite","@id":"http:\/\/localhost:9090\/#website","url":"http:\/\/localhost:9090\/","name":"Ray Sayz","description":"Nowhere, everywhere ... now","publisher":{"@id":"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/localhost:9090\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/localhost:9090\/#\/schema\/person\/00e3de6ea3cf1408f8378a99a51d1ed9","name":"raysayz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/localhost:9090\/#\/schema\/person\/image\/","url":"http:\/\/localhost:9090\/wp-content\/uploads\/2024\/06\/raysayz_upscaled.png","contentUrl":"http:\/\/localhost:9090\/wp-content\/uploads\/2024\/06\/raysayz_upscaled.png","width":800,"height":800,"caption":"raysayz"},"logo":{"@id":"http:\/\/localhost:9090\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/localhost:9090"],"url":"http:\/\/localhost:9090\/author\/raysayz\/"}]}},"_links":{"self":[{"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/posts\/41"}],"collection":[{"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":2,"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":43,"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/posts\/41\/revisions\/43"}],"wp:attachment":[{"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:9090\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}