As an experienced website operator proficient in AnQiCMS, I am well aware of the importance of efficiently and correctly integrating third-party services in the process of content management and website optimization.Especially for the JavaScript push code of search engines, AnQiCMS provides a dedicated and convenient solution.
Integrate JS Push Code in AnQiCMS Template
In modern website operation, maintaining a good interaction with search engines is the key to improving content inclusion and exposure rate.Although mainstream search engines like Baidu and Bing provide API interfaces for link active push, some platforms, such as 360 Search and Toutiao Search, mainly implement automatic submission by embedding JavaScript code in web pages.pluginJsCodeTags that allow website operators to easily integrate these push scripts into website templates without directly modifying the template files.
The advantage of this mechanism lies in the fact that all third-party JS push codes can be configured and managed统一 in the AnQiCMS backend.When updating, adding, or removing JS code for a platform, simply perform the operation in the background, and the system will automatically render it to the specified template location.This significantly reduces maintenance costs, minimizes errors that may be introduced by manual template modifications, and also ensures that the code takes effect in a timely manner.
Backend operations for configuring the JS push code
Use correctlypluginJsCodeTags, first you need to perform the relevant configuration in the AnQiCMS backend management interface.You can go to the 'Feature Management' under the 'Link Push' module.In this module, you will find an area named '360/Top Stories etc. JS Auto Submission'.
Here, you need to fully paste the JavaScript push code obtained from the corresponding search engine platform into the specified input box. Please note that when pasting, it must include<script>The start and end parts of a tag, for example: <script>...</script>.AnQiCMS will be responsible for storing it as a whole and for the subsequent template rendering.This centralized management approach separates the front-end and back-end logic of the website, which helps keep the website code clean and secure.
called in the templatepluginJsCodetags
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 in the template where you want them to be displayed.pluginJsCodeLabel it as such. Typically, these push scripts are placed in the HTML page's<head>tag, or</body>before the closing tag to ensure they execute promptly when the page loads.
The specific template calling method is:
{{- pluginJsCode|safe }}
Among them,pluginJsCodeIt is a placeholder for the JS code content you configure in the background.|safeThe filter plays a crucial role here.AnQiCMS's template engine defaults to escaping output content to prevent cross-site scripting (XSS) attacks.However, for JavaScript code, we do not want it to be escaped, but rather want it 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.
In addition,{-Prefix (i.e.,{{-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 clean, 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 pages, thereby effectively improving the search engine's crawling and indexing efficiency for its content, providing strong support for the SEO optimization of the website.
Common Questions and Answers (FAQ)
Why do I need to use in a template callpluginJsCodewhen|safeFilter?
Answer:|safeFilters are required because the AnQiCMS template engine, for security reasons, defaults to escaping all output HTML content to prevent cross-site scripting (XSS) attacks. If you do not use|safeYour JavaScript code will not be executed by the browser as a script, but will be displayed as plain text on the page, which will cause the push feature to fail.|safeExplicitly tell the template engine that this section of content is safe and does not require escaping.
Question: Why is the front-end page not displaying or the feature not working after I paste the JS code into the backend?
Answer: There may be several reasons. First, please check if you have correctly pasted the complete JavaScript code, including<script>and</script>Labels. Next, confirm that you have used the correct call tag in the template.{{- pluginJsCode|safe }}.Additionally, if you are using a CDN or cache, please try to clear the website cache and CDN cache, and force refresh the browser (Ctrl+F5) to ensure that the latest page is loaded.
Q:pluginJsCodeCan tags insert JS code into any position on the page? For example, only into the header of a specific article page?
Answer:pluginJsCodeTags are a system-wide method for inserting JS code, which will insert the configured JS code into all pages that call this tag. If you need to insert JS code on a specific page or under specific conditions, you usually need to use more advanced template logic to judge (for example,{% if %}Statement), or implement through other finer-grained custom JS injection features provided by AnQiCMS, rather than relying on it alone.pluginJsCodeLabel.pluginJsCode主要用于those JS scripts that need to exist globally, such as the site-wide statistics or push codes.