Before I begin on this topic, I know there are several plugins that let you include some amount of php scripting on a per page or post basis or on a whole. However, the purview of this post is not to use plugins but to make completely independent or standalone scripts that run seamlessly through your website where you need it. This means they will not just use php but include some amount of jQuery and ajax code.
The key to using standalone php scripts is to create your own plugins and leverage the power of WordPress shortcodes.
A plugin in WordPress is simply a php file in the plugin folder that has the required plugin template up top for WordPress to recognize it as such. Basically, anything you put inside this file will do something in WordPress.
Here’s a tutorial to building a simple WordPress plugin.
The next piece of the puzzle is making short codes that implement any functions or classes you write in the plugin file. And that’s about it! Really, it is that simple to include complete scripts in your WordPress install that work free of the theme or installation.
Yes, there are several other considerations to ensure that the plugin works seamlessly across various installations and does not depend on the URL or other things but that is the simplicity of a WordPress plugin in that it lets you do whatever you want with WordPress without worrying about the theme in place.
By the way with a plugin you can include any custom jQuery code and get it hooked into the system only where shortcodes are used. This reduces the burden on the CMS in that it need not load code custom made by you on every single page and post.