{"id":425,"date":"2017-12-13T10:44:16","date_gmt":"2017-12-13T10:44:16","guid":{"rendered":"http:\/\/rifetheme.com\/docs\/docs\/installation-updating\/installing-the-child-theme\/changing-theme-functions\/"},"modified":"2018-01-30T15:49:41","modified_gmt":"2018-01-30T15:49:41","slug":"changing-theme-functions","status":"publish","type":"docs","link":"https:\/\/rifetheme.com\/apollo13-framework\/docs\/modifications-of-theme\/changing-theme-functions\/","title":{"rendered":"Changing Theme Functions"},"content":{"rendered":"<blockquote>\n<p class=\"warning\">This example might not be up to date and cause of this might not work. It is only here to demonstrate the idea.<\/p>\n<\/blockquote>\n<p>Whenever you make modification in theme functions, you are facing risk of\u00a0<strong>losing your changes with theme update<\/strong>. As we already know using\u00a0<strong><a href=\"http:\/\/rifetheme.com\/apollo13-framework\/docs\/installation-updating\/installing-child-theme\/\">child theme<\/a>\u00a0<\/strong>saves us in this situation.<\/p>\n<p>Lets look at example situation when you asked for some modification on our <a href=\"http:\/\/rifetheme.com\/apollo13-framework\/docs\/getting-started\/support-forum\/\">support forum<\/a> and you received code that changes few lines in PHP.<\/p>\n<p>Lets say you had to change code:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">get_search_form(false)<\/code><\/pre>\n<p>to<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">'Search form:'.get_search_form(false)<\/code><\/pre>\n<p>First we have to find in which function was this change. We look at code:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">\/*\r\n * Header search form\r\n *\/\r\nif(!function_exists('a13_header_search')){\r\n    function a13_header_search() {\r\n        return\r\n            '&lt;div class=\"search-container\"&gt;'.\r\n            '&lt;div class=\"search\"&gt;'.\r\n            '&lt;span class=\"icon-search open tool\"&gt;&lt;\/span&gt;'.\r\n            get_search_form(false).\r\n            '&lt;span class=\"icon-cross close tool\"&gt;&lt;\/span&gt;'.\r\n            '&lt;\/div&gt;'.\r\n            '&lt;\/div&gt;';\r\n    }\r\n}<\/code><\/pre>\n<p>Now that we found whole function body, instead of doing modification in main theme code, we first copy this function to\u00a0<strong>child theme<\/strong>.<br \/>\nTo do it open\u00a0<code>functions.php<\/code> <strong>in child theme<\/strong>\u00a0and drop above code at end of file. There will be already some code in this file, it so you should add your code after such comment code:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">\/*\r\n * Add here your functions below, and overwrite native theme functions\r\n *\/<\/code><\/pre>\n<p>So in result you should have(in\u00a0<code>functions.php<\/code>\u00a0file):<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">\/*...some default code above... *\/\r\n \r\n \r\n\/*\r\n * Add here your functions below, and overwrite native theme functions\r\n *\/\r\n \r\n\/*\r\n * Header search form\r\n *\/\r\nif(!function_exists('a13_header_search')){\r\n    function a13_header_search() {\r\n        return\r\n            '&lt;div class=\"search-container\"&gt;'.\r\n            '&lt;div class=\"search\"&gt;'.\r\n            '&lt;span class=\"icon-search open tool\"&gt;&lt;\/span&gt;'.\r\n            get_search_form(false).\r\n            '&lt;span class=\"icon-cross close tool\"&gt;&lt;\/span&gt;'.\r\n            '&lt;\/div&gt;'.\r\n            '&lt;\/div&gt;';\r\n    }\r\n}<\/code><\/pre>\n<p>Now you can make your modification and in\u00a0<strong>final result<\/strong>\u00a0have:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">\/*...some default code above... *\/\r\n \r\n \r\n\/*\r\n * Add here your functions below, and overwrite native theme functions\r\n *\/\r\n \r\n\/*\r\n * Header search form\r\n *\/\r\nif(!function_exists('a13_header_search')){\r\n    function a13_header_search() {\r\n        return\r\n            '&lt;div class=\"search-container\"&gt;'.\r\n            '&lt;div class=\"search\"&gt;'.\r\n            '&lt;span class=\"icon-search open tool\"&gt;&lt;\/span&gt;'.\r\n            'Search form:'.get_search_form(false).\r\n            '&lt;span class=\"icon-cross close tool\"&gt;&lt;\/span&gt;'.\r\n            '&lt;\/div&gt;'.\r\n            '&lt;\/div&gt;';\r\n    }\r\n}<\/code><\/pre>\n<p>You have now overwritten main theme function, and your version will be loaded.<\/p>\n<p>If you activate main theme instead, then your change won&#8217;t be loaded.<\/p>\n<blockquote>\n<p class=\"info\">Most interesting functions you will find in\u00a0<strong>advance\/utilities<\/strong>(in main theme) , but there are more functions that you can change in child theme. All functions that can be overwritten has before its definition code:\u00a0<code>if(!function_exists('function_name'))<\/code>.<\/p>\n<p>If you wish to change other functions ask on our forum for support in that case, or just don&#8217;t bother with child theme and change main theme(if you understand implications;-) ).<\/p><\/blockquote>\n","protected":false},"author":1,"featured_media":0,"parent":8354,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_tag":[],"class_list":["post-425","docs","type-docs","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/docs\/425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":2,"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/docs\/425\/revisions"}],"predecessor-version":[{"id":8914,"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/docs\/425\/revisions\/8914"}],"up":[{"embeddable":true,"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/docs\/8354"}],"next":[{"title":"Overwriting JavaScript Files","link":"https:\/\/rifetheme.com\/apollo13-framework\/docs\/modifications-of-theme\/overwriting-javascript-files\/","href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/docs\/426"}],"prev":[{"title":"Adding Custom CSS","link":"https:\/\/rifetheme.com\/apollo13-framework\/docs\/modifications-of-theme\/custom-css\/","href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/docs\/424"}],"wp:attachment":[{"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/rifetheme.com\/apollo13-framework\/wp-json\/wp\/v2\/doc_tag?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}