{"id":5987998,"date":"2015-04-07T15:06:06","date_gmt":"2015-04-07T15:06:06","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/calling-from-functionsphp\/"},"modified":"2016-08-24T14:29:27","modified_gmt":"2016-08-24T14:29:27","slug":"calling-from-functionsphp","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/calling-from-functionsphp\/","title":{"rendered":"Calling From Functions.php"},"content":{"rendered":"<p>Philipp,<\/p>\n<p>In my <code>functions.php<\/code> file, I&#8217;m attempting to call <code>custom-pos-header.php<\/code> which contains only one line: <code>&lt;?php echo do_shortcode(&#039;[moduleposition id=&quot;1&quot;]&#039;); ?&gt;<\/code><\/p>\n<p>I keep getting this message: <code>Fatal error:  Call to undefined function do_shortcode() in \/www\/mySite\/wp-content\/themes\/myTheme\/inc\/custom-pos-header.php on line 1<\/code><\/p>\n<p>After Googling for a couple days, I came across numerous suggestions saying to do it through Ajax. Here&#8217;s the entry I made in my <code>functions.php<\/code> file:<\/p>\n<pre><code>\/\/ embed the javascript file that makes the AJAX request\nwp_enqueue_script( &#039;load-mobile-header-ajax&#039;, get_template_directory_uri() . &#039;\/js\/ajax.js&#039;, array( &#039;fnd-jquery&#039; ) );\nwp_localize_script( &#039;load-mobile-header-ajax&#039;, &#039;myAjax&#039;, array( &#039;ajaxurl&#039; =&gt; admin_url( &#039;admin-ajax.php&#039; ) ) );\n\/\/ THE AJAX ADD ACTIONS\nadd_action( &#039;wp_ajax_load_mobile_header&#039;, &#039;load_mobile_header&#039; );\nadd_action( &#039;wp_ajax_nopriv_load_mobile_header&#039;, &#039;load_mobile_header&#039; ); \/\/ need this to serve non logged in users\nfunction load_mobile_header(){\n\tinclude(&#039;..\/wp-content\/plugins\/module-positions\/module-positions.php&#039;);\n\t$mobile_header = get_template_directory_uri().&#039;\/inc\/custom-pos-header.php&#039;;\n\treturn $mobile_header;\n\tdie();\n}<\/code><\/pre>\n<p>Here is the entry I&#8217;ve added to my <code>ajax.js<\/code> file:<\/p>\n<pre><code>jQuery.ajax({\n  \/\/ previous type was &quot;POST&quot;\n  type:&quot;GET&quot;,\n  url: ajaxurl,\n  data: {\n    action : &quot;load_mobile_header&quot;\n  },\n  success:function(data){\n    window.console.log(data);\n  },\n  error:function(errorThrown){\n    window.console.log(errorThrown);\n  }\n\n});<\/code><\/pre>\n<p>Any ideas on what I&#8217;m doing wrong?<\/p>\n<p>https:\/\/wordpress.org\/plugins\/module-positions\/<\/p>\n","protected":false},"template":"","class_list":["post-5987998","topic","type-topic","status-closed","hentry","topic-tag-do_shortcode","topic-tag-fatal-error"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5987998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5987998\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5987998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}