0

I have added some custom ajax calls and functionality on my WordPress site. I added code in function.php which is placed in wp_includes folder. It was working fine but from the last 2 weeks, my custom functions automatically removed from functions.php file. what is the solution of this? I am new to WordPress. Any help would be highly appreciable.

1 Answer 1

1

The simplest advice is that you should never edit what are generally know as Core WordPress files, that includes adding new files within the wp-includes and wp-admin directories.

The simple reason why this is not a good idea is that they are replaced when WordPres updates - deleting any changes or additional files - which I presume is the reason your files were also removed recently.

Instead, you should add changes to your own theme or a custom plugin - the theme is the easiest route in most cases, but again you should avoid to edit things you don't control, so don't edit a theme you have bought or downloaded, instead learn how to create a child theme which you can safely edit, knowing that your updates will not get lost.

Once you have your child theme - or custom plugin - you can add your code there - in a theme the easiest place is inside the functions.php file

3
  • Thanks for you reply. May I know the reason of why it auto delete automatically without upgrading wordpress and theme. The second question is how about using "code snippet" plugin. is that a good idea to use that plugin. I have multiple apis call through ajax and bunch of javascript. Commented Jan 18, 2021 at 9:53
  • WordPress replaces all files and folders with new ones - this keeps things organised and removes outdates / unrequired files - it might also help with security - theme / plugins developers also know this means they should not update core files, so this reduces bad practise. Commented Jan 18, 2021 at 9:58
  • As for the plugin, I have no idea - you should use the route you find most comfortable and see what works. Commented Jan 18, 2021 at 9:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.