Trying to edit functions.php to add code to exclude category from blog, but keep getting error message!

Hi, I’m trying to edit functions.php to add code to exclude a category from displaying on the blog, but I keep getting an error message!

Here’s the code:

function x_exclude_cat_from_blog($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('cat', '-5');
}
}
add_action('pre_get_posts', 'x_exclude_cat_from_blog');

Here’s the error message:

Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.

It seems to have started coming up with that error message after recent updates, as I’s already added in some code so my global block would appear at the footer of every page and even when I don’t add any new code and just go to update the functions.php file, it comes up with the error message!

I have no idea what’s causing the error message, but I’m hoping you might know!

I’ll put the URL in a secure note as it’s on a temp link.

Thanks!

Hi @core365,

Thank you for writing in, I have tested that code on my dev site and I did not get any error. Please add a WP_DEBUG to your wp-config.php file, we might able to get a clue on what is causing the issue.

It could be a conflict with your other functions, plugins, caching or PHP version.

Let us know how it goes,
Cheers!

Hi, sorry, but I’ve looked at the link for WP_DEBUG and I’m even ore confused now! I’m not a developer, I have some knowledge of CSS (enough to get me by, but mainly helped out by yourselves!) and I use your theme because it’s the easiest one to get a website looking exactly how I want it and my knowledge of back end stuff is very limited, so I’d really appreciate it if you could let me know exactly what I need to add to the wp-config.php file as I was going to add in this - is it correct?

define( 'WP_DEBUG', true );
define( 'WP_DEBUG', false );

Thanks!

Hello @core365,

There seems to be an issue in your server is you are still receiving the error message:

Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.```

You might want to check out this link:
- https://wordpress.org/support/topic/cant-edit-main-theme-php-files-after-upgrading-to-4-9/page/2/

I would highly recommend that you login to your FTP and manually edit your child theme's functions.php file to add your custom php function. This is much more faster than to resolve your server issue why you cannot use the WP File Editor.

Hope this makes sense.

Hi @runel,

I checked the link, thanks, and it seems as though it’s unresolved! I’ve just done as you recommended and manually edited it through my FTP.

Thanks for looking into it!

You are most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.