Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
2  
Exactly why would you want to remove a piece of PHP which outputs a date, to replace it with a pice of Javascript which outputs a date generated by PHP? This seems like loading your car onto the back of a truck and driving the truck around instead of just driving the car. –  Marc B Sep 12 '11 at 15:59
 
Its so that the date of the website doesn't get put into the Google SERP for SEO reasons. –  Mohammad G Sep 12 '11 at 16:12
add comment

2 Answers

up vote 2 down vote accepted

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()
share|improve this answer
 
Yes that did it! Thank you so much :D Any idea on how to remove the tooltip it creates? –  Mohammad G Sep 12 '11 at 17:13
 
That's probably due to the title attribute. Browsers tend to use the info in that for tooltips. –  Marc B Sep 12 '11 at 17:15
 
Awesome I removed it :) –  Mohammad G Sep 13 '11 at 2:47
add comment

I don't think you understood the instructions properly. You shouldn't be doing anything to the PHP function that creates the datestamp. You need to replace the piece of code that calls the function in your template files.

There are 3 files you need to look at in your template - index.php, single.php, and archive.php. In those files look for the part of the file that displays the date. It looks like your template uses the function twentyten_posted_on to display the date so look for that. Once you find it, replace the whole thing with <script language="javascript" type="text/javascript">document.write("<?php the_time('F jS, Y') ?>");</script>

If you can't find it, post the contents of index.php so we can see how your template works.

share|improve this answer
 
No its just that I am using a different theme than the person who explains this. My theme uses the function like you said to report the time so I need to edit the function. –  Mohammad G Sep 12 '11 at 16:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.