【问题标题】:Insert php date using Javascript in Wordpress Theme在 Wordpress 主题中使用 Javascript 插入 php 日期
【发布时间】:2011-12-11 05:10:57
【问题描述】:

对于我的 wordpress 网站,我正在尝试删除当前在我的 SERP(搜索页面结果描述)中的 Google 时间戳。

为此,我必须使用 javascript 来获取时间并报告回来。

您可以参考这个链接:http://www.andrewkeir.com/remove-wordpress-post-datestamp-timestamp-google-serps/

这里还有另一个问题:Need to insert javascript into php code [Wordpress Website]

我的模板文件中的代码是:

$out .= '<div class="info"><a class="date-left"></a><a href="'.get_month_link($year, $month).'" class="date">'.get_the_time('F j, Y').'</a><a class="date-right"></a>

我需要让这段代码在它的位置上工作:

<script language="javascript" type="text/javascript">document.write("<?php the_time('F jS, Y') ?>");</script>

感谢有关如何执行此操作的任何帮助/指导。

【问题讨论】:

    标签: php javascript wordpress date


    【解决方案1】:

    基本上,您引用的第一篇文章告诉您,您需要使用 Javascript 包装确定时间的代码(在您的情况下为“get_the_time('F j, Y')”部分),该代码将编写确切的相同的输出到文档。因此,如果您采用现有代码:

    $out .= '<div class="info"><a class="date-left"></a><a href="'.get_month_link($year, $month).'" class="date">'.get_the_time('F j, Y').'</a><a class="date-right"></a>
    

    你可能想做这样的事情:

    $out .= '<div class="info"><a class="date-left"></a><a href="'.get_month_link($year, $month).'" class="date"><script language="javascript" type="text/javascript">document.write('.get_the_time('F j, Y').');</script></a><a class="date-right"></a>
    

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 2016-06-21
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 2021-11-30
      相关资源
      最近更新 更多