一个开发了我使用的注释插件的插件开发人员指示我添加以下JavaScript:

function WPACLoadMoreComments() {
  window.WPACLoadMoreCount = window.WPACLoadMoreCount || 1;
  var url = (new Uri(location.href)).replaceQueryParam('WPACTake', window.WPACLoadMoreCount * 20).toString();
  if (WPAC.LoadComments(url, {updateUrl: false})) {
    window.WPACLoadMoreCount++;
  }
}


我认为他的意思是将其放入functions.php中,但是当我插入此代码时,该站点不会加载。我试图在最后插入它,我试图用

<?php

the function...

?>


我如何正确地做到这一点?

最佳答案

将以下代码添加到您的functions.php文件中

function comment_script(){
$html = "<script type='text/javascript'>
   function WPACLoadMoreComments() {
     window.WPACLoadMoreCount = window.WPACLoadMoreCount || 1;
     var url = (new Uri(location.href)).replaceQueryParam('WPACTake',   window.WPACLoadMoreCount * 20).toString();
  if (WPAC.LoadComments(url, {updateUrl: false})) {
    window.WPACLoadMoreCount++;
  }
}
</script>";
echo $html;
}
add_action('wp_footer','comment_script');

10-06 02:48