Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to insert javascript into php code [Wordpress Website]

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

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

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()

    ),

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>

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.

like image 576
Mo Beigi Avatar asked Sep 14 '26 09:09

Mo Beigi


1 Answers

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

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) 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()
like image 84
Marc B Avatar answered Sep 16 '26 23:09

Marc B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!