Home > Enterprise >  text in backend due to date
text in backend due to date

Time:06-11

I succeded to show in wordpress backend a text, here is the code

function my_message() {
    ?>
    <div >
        <p><?php _e( 'Customer Care Attivo.', 'my_plugin_textdomain' ); ?></p>
    </div>
    <?php
}
add_action( 'admin_notices', 'my_message' );

Now i would like to show this text just before a date and after that date show another message

somebody can help on me?

CodePudding user response:

You can use the PHP date function. Inside of your my_message function you can use if else clauses.

function my_message() { ?>
    <div >
        <p>
        <?php
            $today = date("Y-m-d"); // get today's date
            $otherday = date('Y-m-d', strtotime('2022-08-10')); // the day message change
            if ( $today > $otherday ): // if today is past otherday
                _e( 'New message', 'my_plugin_textdomain' );
            else: // if today is otherday or today is not yet otherday
                _e( 'Old message', 'my_plugin_textdomain' );
            endif;
        ?>
        </p>
    </div>
<?php
}
add_action( 'admin_notices', 'my_message' );
  • Related