將 disqus 在任意 WordPress 頁面調用,採用 shortcode 短代碼形式。

標籤: 

正在查看 1 個帖子:1-1 (共 1 個帖子)
  • 作者
    帖子
  • 詩語
    管理員
    • 文章數量: 5,930
    @feibisi
    樓主

    將下面代碼添加到主題的 functions.php 文件中

    add_shortcode('disqus-inserter', 'disqus_embed');
    function disqus_embed() {
        global $post;
        wp_enqueue_script('disqus_embed','https://example.disqus.com/embed.js');
        return '<div id="disqus_thread"></div>
        <script type="text/javascript">
            var disqus_title = "'.$post->post_title.'";
            var disqus_url = "'.get_permalink($post->ID).'";
            var disqus_identifier = "example-'.$post->ID.'";
        </script>';
    }

    然後將上方的 example 改成

    https://example.disqus.com/embed.js

    你已經註冊的 disqus 地址,如:

    https://weixiaoduo.disqus.com/embed.js

    在其他頁面調用的時候採用 [disqus-inserter] 簡碼實現。

    效果如下:

正在查看 1 個帖子:1-1 (共 1 個帖子)
  • 哎呀,回覆話題必需登錄。

話題信息

  • 當前位於:定製問題
  • 0 條回覆
  • 1 個參與人
  • 最後回覆:<a href="https://bbs.weixiaoduo.com/users/feibisi/" title=" 查看詩語的個人資料" class="bbp-author-link"><span class="bbp-author-name"> 詩語</span></a>
  • 上次活動:<a href="https://bbs.weixiaoduo.com/topic/28053/" title=" 將 disqus 在任意 WordPress 頁面調用,採用 shortcode 短代碼形式。">6 年、 7 月前</a>