0

Our clients would like to schedule changes made to a given page (for instance by displaying the link to register to an event).

Typically, the same page (/registration) should display (before the registration opening): "The registrations will be open by ..."

Once the time comes, the same page should display: "Registrer by clicking on this link..."

I tried to follow the below procedure, but it doesn't help: https://en.support.wordpress.com/schedule-a-page/

Is there a way to have 2 versions (or revision - one published and one as draft) where the draft version would become published automatically?

Or a way to have two different pages sharing the same url (one being published until a given date and the other one getting published right after the first gets unpublished)?

Preferably, this procedure should not involve a developer every time a bit of text is changed on a page.

Thanks in advance

1

you can do this with a shortcode like this

add_shortcode("custom_text_se282078", function ($attr, $content, $tag) {

    $result = "";

    if (date_i18n("H") > $attr["time"]) {
        $result = $attr["text_after"];
    } else {
        $result = $attr["text_before"];
    }

    return $result;

});

with that you just have to put that in the page :

[custom_text_se282078 time="10" text_before="text before 10 h" text_after="texte after 10 h"]

  • it actually does the trick, but requires a developer to code and deploy the new short code, which is not "user friendly" – E. Jaep Oct 6 '17 at 14:13
  • you don't explain what is "user friendly" in your inital question. can you give more details ? – mmm Oct 7 '17 at 9:12
  • you are right, I'll edit de question. I meant without having to involve a developer every time we need to change a piece of text in the page. – E. Jaep Oct 9 '17 at 9:27
  • 1
    Make it [display_between_time start="2017-10-09 15:00:00" start="2017-10-09 16:00:00"]Register now![/display_between_time] and check those dates against the current time to give full control to users. Just have multiple of those if you want to hide some and show other content. – janh Oct 9 '17 at 10:05
  • I edit my answer, you can use parameters in the shortcode. in this parameters you can put links, post ID or other data. – mmm Oct 9 '17 at 10:06
0

Based on @mmm answer, my code look like this:

extract(shortcode_atts(array(
    'start' => ''
), $attributes));

extract(shortcode_atts(array(
    'end' => ''
), $attributes));

if (($start_timestamp = strtotime($start)) === false) {
    $error = new WP_Error('unable to parse', 'Unable to parse start timestamp', $start);
    scheduler_log($error);
    return '';
}

if (($end_timestamp = strtotime($end)) === false) {
    $error = new WP_Error('unable to parse', 'Unable to parse end timestamp', $end);
    scheduler_log($error);
    return '';
}

date_default_timezone_set("Europe/Zurich");
$now = strtotime("now");

if($now>=$start_timestamp && $now<=$end_timestamp){
    return $content;
}
else{
    return '';
}
0

If you want a non-shortcode based solution, the free Revisionary Plugin offers this functionality: https://wordpress.org/plugins/revisionary/

One important note: The plugin hasn't been updated in several years. I have used it in the past and it has worked well in the past. However, I don't know if it is still under active development.

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.