需要将javascript插入php代码[Wordpress网站] [英] Need to insert javascript into php code [Wordpress Website]

查看:34
本文介绍了需要将javascript插入php代码[Wordpress网站]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For my wordpress website I am trying to remove the Google timestamp that is currently in my SERP (search page result description.)

为此,我必须使用javascript来获取时间并向其报告.

To do this I must use javascript to get the time and report it back.

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

You may want to refer to this link: http://www.andrewkeir.com/remove-wordpress-post-datestamp-timestamp-google-serps/

function twentyten_posted_on() {
printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    'meta-prep meta-prep-author',
    sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
        get_permalink(),
        esc_attr( get_the_time() ),
        get_the_date()

    ),

在上面的代码中,get_the_time()和get_the_date()是要替换为以下javascript的部分:

In the above code get_the_time() and get_the_date() are the parts are want to replace with the following javascript:

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

要执行此操作的PHP代码是什么!我已经尝试了100万种都会导致错误的东西,所以我认为我可能会忽略某些东西.

Whats the PHP code to do this! I have tried a million things which all result in error's so I think I may be overlooking something.

推荐答案

好吧,因为我们必须在SEO祭坛前鞠躬...

Ok, since we must be bow before the Altar of SEO...

a)生成您的JS代码段:

a) Generate your JS snippet:

$date = get_the_time('F jS, Y');
$js = <<<EOL
<script language="javascript" type="text/javascript">document.write('$date');</script>
EOL;

b)将该代码段插入链接:

b) Insert that snippet into the link:

sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
        get_permalink(),
        $js,
        get_the_date()

这篇关于需要将javascript插入php代码[Wordpress网站]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆