0
votes

I have this conditional function inside the wp-content/themes/twentythirteen-child/content.php template of my Twenty Thirteen child theme to add banners above certain posts on the blog archive page.

if (in_category(get_theme_option('banner_1_category')) 
      && (! is_category(get_theme_option('banner_1_category'))))
{ 
        echo "<div id=\"banner-1\"><h3>".get_theme_option('banner_1_text')."</h3></div>";
} 
....

And it's working without problems.

Now I'm moving to an Avada child theme and the corresponding template is wp-content/themes/avada-child/templates/blog-layout.php. When I put the above code within this template, I get the following error:

Fatal error: Call to undefined function in_category()

I don't quite understand how this can be "undefined" since in_category() is a core function of WordPress. I've Googled the error without many results. It seems that similar errors have been solved by adding a require_once() to the wp-load.php file.

require_once('/home/my-server-path/wp-load.php');

I tried putting that ahead of my conditional and it made no difference.

Why is a core function of WordPress not working in Avada and what can I do to fix it?

I'm running the latest versions of WordPress (5.2.3) and Avada (6.0.3)


EDIT:

Failed to mention that the conditional function above is being injected into the templates via an include

include 'my-path/includes/banners.php';

Working:

wp-content/themes/twenty-thirteen-child
    ↳ archive.php ('get_template_part' content-cpt.php) 
    ↳ content-cpt.php ('include' includes/banners.php)
    ↳ includes
        ↳ banners.php

(Fatal error: Call to undefined function in_category()):

wp-content/themes/avada-child
    ↳ archive.php ('get_template_part' templates/blog-layout.php)
    ↳ templates
        ↳ blog-layout.php ('include' includes/banners.php)
    ↳ includes
        ↳ banners.php
1
I recommend doing a manual update for your WordPress instance. wordpress.org/support/article/updating-wordpress/#manual-update Let me know if that resolves it. - Brian Nezhad
@Farhad, this is already a brand new installation. And when I switch back to my old theme, there is no error. This is only an issue within Avada theme. - Sparky
I figure, but I want you to do it again because the way sometimes core functions get installed can be broken. If that didn't help then we can move into looking at the core file itself. - Brian Nezhad
@Farhad - I removed and re-uploaded the wp-admin and wp-includes directories. I re-uploaded all core files except wp-config.php. I did not re-upload anything from wp-content because nothing in these new files are being used... none of the newer themes, nor Akismet & Hello Dolly. None of this made any difference. Problem persists. - Sparky
Can you try get_the_category_list, developer.wordpress.org/reference/functions/…, and tell me what you get? - Brian Nezhad

1 Answers

0
votes

I changed the include to a get_template_part() and it's all working again. I had to modify the file name with a slug to blog-banners.php in order to do it this way.

get_template_part('includes/blog', 'banners');

However, I cannot explain why the WordPress core functions within the include in Twenty Thirteen are working fine, but the same WordPress core functions within the same include within a different template are giving "undefined" errors in Avada. Both themes use a series of get_template_part() functions to end up on the template where I inserted my conditional. The only difference is that the Avada template where my include was inserted is within a subdirectory of the theme, but in Twenty Thirteen it's in the root of the theme.

I'll accept my own answer until somebody posts a better one that explains this fatal error in detail.