Adding JavaScript is not recommended. The
First, scripts prevent developers from writing good code. One of the ways to run a website well is to rely on clean coding methods. Bad JavaScript can get in the way. Second, when updating the theme or plug-in file, the user-defined JavaScript instructions will be lost. JavaScript belongs to the title of the topic, which can be edited. There are PHP files, but don’t do this here. Finally, if you want to create a sub theme and apply custom JavaScript in it to bypass the problem, do not do so. Use JavaScript headers. PHP or footer. Updating the PHP file may accidentally conflict with a plug-in running on the site. Because the site does not know how to handle these concurrent requests, the speed may be much slower, or the server may be completely offline. The
Note: this rule only applies to word press developers who actually use third-party themes or plug-ins. If you want to create your own themes and plug-ins, you can add JavaScript directly to the header file. But you may want to use a queue system, as described here. Rule \3: if a separate file is generated for JavaScript and it is required not to add JavaScript code directly to WordPress files or pages, how do you enter it? There are two ways. One is to create a separate JavaScript file. The other is to specify in rule \4 that you can use the word press plug-in to add custom JavaScript. The
It has been mentioned that adding custom JavaScript directly to WordPress may be very bad, potentially leading to serious problems such as dead white screen. However, if the script is only applied to one page, you need to insert the code at the location where the code belongs, instead of adding the code, and disable the rest of the sites through unnecessary HTTPS requests. Therefore, you must create a separate JavaScript file. WordPress Codex contains several steps to perform the following file operations: It is recommended that you easily refer to the following: The
Whether it is a single script or multiple scripts, you must define a function for each in a file. For example: androg then use the following script to call the file from the web site header (you can add it to the header using a plug-in): Finally, you must call the actual JavaScript function defined in the file. Even if there is only one script, it must be defined in the code. If JavaScript is applied to an entire page or site, you can add the following JavaScript calls to the title: If JavaScript must run somewhere on the page, it must move within the body of the site. The
Male rule \4:the WordPress plug-in uses the word press plug-in. Thank you very much. For JavaScript, the following plug-ins help avoid problems when JavaScript is placed directly in word press files. Instead, these plug-ins only notify the server to invoke the script when the task \