【问题标题】:Add <script> in wordpress post在 wordpress 帖子中添加 <script>
【发布时间】:2021-11-22 15:00:49
【问题描述】:

我使用 elementor 插件作为目录,但我有一个代码可以最小化桌面上的目录。 我想在我使用它的网站的所有位置禁用目录。

我的代码是:

<script> 
jQuery(document).ready(function($) { 
var delay = 100; setTimeout(function() { 
$('.elementor-widget-table-of-contents').addClass('elementor-toc--collapsed');
 $('.elementor-toc__body').css('display', 'none'); }, delay); 
}); 
</script>

如何在我的网站上正确添加此代码?

【问题讨论】:

    标签: javascript wordpress elementor tableofcontents disable


    【解决方案1】:

    您可以使用插件Code Snippets 将您的sn-p 添加到您网站的所有页面。它支持 PHP sn-ps,但你可以直接回显你的脚本:

    <?php
    echo "<script> 
          jQuery(document).ready(function($) { 
              var delay = 100; setTimeout(function() { 
                  $('.elementor-widget-table-of-contents').addClass('elementor-toc--collapsed');
                  $('.elementor-toc__body').css('display', 'none'); }, 
              delay); 
       }); 
       </script>"
    ;
    ?>
    

    【讨论】:

      【解决方案2】:

      您的客户端解决方案 (jQuery/Javascript + CSS) 不是删除 TOC 的好主意,因为您的源代码会很脏并且不会更改。

      您必须通过更改插件设置或使用PHP/Wordpress函数等逻辑解决方案来解决此问题。

      这里有一个更好的解决方案:

      https://wordpress.org/support/topic/hide-or-remove-table-of-content/

      祝你好运

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多