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
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
- 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.Muhammad Haris Riaz– Muhammad Haris Riaz2021-01-18 09:53:51 +00:00Commented 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.Ray– Ray2021-01-18 09:58:07 +00:00Commented 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.Ray– Ray2021-01-18 09:58:33 +00:00Commented Jan 18, 2021 at 9:58