0

Backstory: I am generating posts from rss feeds adding additional content to the post using shortcodes.

Problem is that every time the page is refreshed the shortcodes fire and load new content. This is fine for users, but Googlebot is going to see too many big changes every time it visits the post --- subtle updates for a justified reason or signs of user activity/engagement is good, wholesale changes, not good for SEO.

Question(s): Control caching or Control shortcodes?

1) Ideally there would be some kind of scheduler to control the shortcodes - ie. once a month refresh etc.

2) I'm using WP Super Cache combined with Autoptimize & Speed Up Lazy Load which work well, but there is no apparent provision to cache the shortcode results.

Ideas? I understand this question is short on details, but need to start with what is possible.

thanks

0

You'd want to look up transients Here's a simple example of how you do it.

function showPosts (){
    $posts = get_transient ("my_rss_transient");
    If (!$posts){$posts=getPosts ();}
    /* do showing off stuff here */
}

function getPosts (){
    $posts = /* get posts here*/
    Set_transient ("my_rss_transient", $posts, MONTH_IN_SECONDS);
     return $posts
}

The transient should be saved for each month. Sorry for the bad formatting.

EDIT: I agree with mark in the comments. Look up his way of doing it rather than this.

  • 1
    hopefully at some point in the (distant) future people will finally get the fact that transients are not built for deterministic caching as they might expire at any time. If you want deterministic caching, you cache things directly in options. (yes I know I am fighting a war I can not win :) ) – Mark Kaplun Jun 24 '17 at 6:13
  • .... the worse thing is that you should never store php objects in the DB. this have a potential of creating a lot of trouble especially if the object structure is changed during the time the value was cached – Mark Kaplun Jun 24 '17 at 6:16
  • Hmm. Never took that into account. Yes. Options would be a better fit here. Thanks for the reminder. You could post an answer instead of me editing the whole thing. – Prasun Jajodia Jun 24 '17 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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