{"id":3888,"date":"2013-06-12T19:05:48","date_gmt":"2013-06-12T19:05:48","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=3888"},"modified":"2013-06-12T19:05:48","modified_gmt":"2013-06-12T19:05:48","slug":"solution-wordpress-fatal-error-call-to-undefined-function","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/solution-wordpress-fatal-error-call-to-undefined-function\/","title":{"rendered":"SOLUTION WordPress Fatal error: Call to undefined function"},"content":{"rendered":"<p>While working with WordPress, at one point of time or the other, you may have come across error message that says: <strong>&#8220;Fatal error: Call to undefined function &#8230; &#8220;.\u00a0<\/strong>In this message, the undefined function could be just about anything such as\u00a0feed_content_type or\u00a0get_adjacent_post or\u00a0wp_get_recent_posts, etc. So how can we solve this? This is exactly what this article is all about. I am going to share a very easy way that you can use in your theme or plugin to gracefully solve and prevent fatal errors from showing up and breaking the normal functionality of your WordPress theme or plugin.<\/p>\n<p><!--more--><\/p>\n<h2>How To Solve\u00a0Fatal error: Call to undefined function &#8230; in WordPress Themes &amp; Plugins<\/h2>\n<p>Now let&#8217;s say that you are working on a WordPress theme. You would like to use the function &#8220;<strong>the_excerpt<\/strong>&#8220;. Now you do not know whether this function has already been declared or not. So to be on the safer side do the following:<\/p>\n<h3>Use the following code in your theme to prevent fatal errors:<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;?php \nif (function_exists('the_excerpt')) \n{ \n\tthe_excerpt(); \n} \n?&gt;<\/pre>\n<p>The above code will first check to see if the function really exists. If the function is already defined and available for use, the excerpt will be fetched and shown on the screen. If not, it will simply not do anything at all. You can also combine the above code with other conditional code to display another result if the function does not exist. Consider the following example:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?php\nif (function_exists('the_excerpt')) \n{ \n     the_excerpt(); \n} \nelse \n{ \n     echo 'The function is Undefined';\n} ?&gt;<\/pre>\n<p>You can do the same thing as above in your plugins as well.<\/p>\n<h3>How to apply the above code to any custom functions in your custom Plugin and prevent fatal errors<\/h3>\n<p>Let&#8217;s say you are coding custom plugin. And now you have defined some function such as &#8220;my_function1&#8221;,\u00a0\u00a0&#8220;my_function2&#8221;. Now you want to use these in your plugin and want to avoid showing fatal errors. Simply apply the function_exists function prior to using it and that will solve it. Here are couple of examples:<\/p>\n<h3>Example 1:<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;?php \nif (function_exists('my_function1')) \n{ \n\tmy_function1(); \n} \n?&gt;<\/pre>\n<h3>\u00a0Example 2:<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;?php \nif (function_exists('my_function2')) \n{ \n\tmy_function2(); \n} \n?&gt;<\/pre>\n<h3>\u00a0Example 3:<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;?php \nif (function_exists('this_is_my_custom_function')) \n{ \n\techo this_is_my_custom_function(); \n} \n?&gt;<\/pre>\n<p>As you can see from the above codes, it is really simple. Simply check if the function exists using the function_exists function and that should do it.<\/p>\n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to solve the <em><strong>Fatal error Call to undefined function problem in WordPress<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working with WordPress, at one point of time or the other, you may have come across error message that says: &#8220;Fatal error: Call to undefined function &#8230; &#8220;.\u00a0In this message, the undefined function could be just about anything such as\u00a0feed_content_type or\u00a0get_adjacent_post or\u00a0wp_get_recent_posts, etc. So how can we solve this? This is exactly what this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":114,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,11],"tags":[30],"class_list":["post-3888","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks","category-wordpress-tips-and-tricks","tag-wordpress-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-10I","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/3888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=3888"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/3888\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=3888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=3888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=3888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}