As an experienced AnQiCMS website operator, I know that it is crucial to integrate third-party services efficiently and correctly in the process of content management and website optimization.Especially for the JavaScript push code of search engines, AnQiCMS provides a special and convenient solution.

Integrate JS push code in AnQiCMS template

In modern website operation, maintaining good interaction with search engines is the key to improving content inclusion and exposure rate.Although Baidu and Bing and other mainstream search engines provide API interfaces for active link push, some platforms such as 360 Search and Toutiao Search mainly achieve automatic submission by embedding JavaScript code in the website page.To manage these scripts uniformly, AnQiCMS providespluginJsCodeTags that make it easy for website operators to integrate these push scripts into website templates without having to directly modify the template files.

The advantage of this mechanism lies in the fact that all third-party JS push codes can be configured and managed uniformly in the AnQiCMS backend.When you need to update, add, or remove the JS code for a platform, just perform the operation in the background, and the system will automatically render it to the specified template location.This greatly reduces maintenance costs, reduces errors introduced by manual template modification, and also ensures that the code takes effect in a timely manner.

Configure the background operation of the JS push code

Use correctlypluginJsCodeLabel, first you need to configure it in the AnQiCMS admin interface.You can go to the "Function Management" under the "Link Push" module.In this module, you will find a section named "360/Toutiao and JS Auto Submission".

Here, you need to paste the complete JavaScript push code obtained from the corresponding search engine platform into the specified input box. Please note that when pasting, you must include<script>The start and end tags, for example:<script>...</script>. AnQiCMS will be responsible for storing it as a whole and subsequent template rendering.This centralized management approach separates the front-end and back-end logic of the website, which helps keep the website code neat and secure.

Call in the templatepluginJsCodeTag

It is very intuitive to call these pre-configured JS push codes in the AnQiCMS template. You just need to insert them at the location where you need to display the codepluginJsCodeTags can be placed. Usually, these push scripts are placed in the HTML page<head>tags or</body>before the closing tag to ensure that they can be executed in time when the page is loaded.

The specific template calling method is:

{{- pluginJsCode|safe }}

Among them,pluginJsCodeIs the placeholder for the JS code content you configure in the background.|safeThe filter plays a crucial role here. The AnQiCMS template engine defaults to escaping output content to prevent cross-site scripting attacks (XSS).However, for JavaScript code, we do not want it to be escaped, but rather to be parsed and executed as pure script by the browser.|safeThe filter is used to inform the template engine that the content output here is safe and does not require escaping.

Furthermore,{-Prefix, that is,{{-It is a syntax used to control the removal of leading whitespace when the template is output.In some cases, it helps to keep the generated HTML code neat, avoiding unnecessary blank lines or spaces.

By following these steps, AnQiCMS can ensure that the third-party JS push code is correctly loaded and executed on your website, thereby effectively improving the search engine's crawling and indexing efficiency for its content, providing strong support for your website's SEO optimization.


Frequently Asked Questions (FAQ)

Ask: Why do you need to call in the templatepluginJsCodewhen using|safeFilter?

Answer:|safeThe filter is required because the AnQiCMS template engine, for security reasons, defaults to escaping all output HTML content to prevent cross-site scripting attacks (XSS). If you do not use|safeYour JavaScript code will not be executed by the browser as executable script, but will be displayed as plain text on the page, resulting in the failure of the push function.|safeTell the template engine that this section of content is safe and does not need to be escaped.

What could be the reason if I paste the JS code into the background and the front-end page does not display or the function does not work?

Answer: There may be several reasons. First, please check whether you have pasted the complete JavaScript code correctly in the "Link Push" section of the background "360/Toutiao and other JS automatic submission" part, including<script>and</script>Label. Next, confirm that you have used the correct call label in the template{{- pluginJsCode|safe }}. Also, if you are using a CDN or cache, please try to clear the website cache and CDN cache, and refresh the browser (Ctrl+F5) to ensure that the latest page is loaded.

Question:pluginJsCodeCan the tag insert JS code into any position on the page? For example, only into the header of a specific article page?

Answer:pluginJsCodeThe tag is a system-wide JavaScript code insertion method, which will insert the configured JavaScript code into all pages that call the tag. If you need to insert JavaScript code on a specific page or under specific conditions, you usually need to use more advanced template logic judgment (such as{% if %}statement), or to implement other finer-grained custom JS injection functions provided by AnQiCMS, rather than just relying onpluginJsCode.pluginJsCodeUsed for those JavaScript scripts that need to exist globally, such as site-wide statistics or push codes.