[Video] Dynamic year in Oxygen

Footer text in websites typically have the current year text.

Let’s see how this can be made dynamic i.e., automatically showing the current year in Oxygen.

Step 1

Install and activate Code Snippets plugin if you have not already.

Step 2

Add a new Snippet with a title of say “Current year” having the following code:

function sk_current_year() {
    echo date( 'Y' );
}

You can leave sk_current_year as is or replace it with your desired function name (make sure it does not contain spaces or hyphens).

Step 3

In the Oxygen editor place the cursor wherever you want the current year to appear, then click on Insert Data, then PHP Function Return Value and paste sk_current_year (i.e., the name of the function we created in the earlier step) in the Function Name field and Insert.

The value may not appear in the editor but should work on the frontend.


Posted

in

,

by

Comments

4 responses to “[Video] Dynamic year in Oxygen”

  1. Asbjørn Avatar
    Asbjørn

    Why not use the date function directly?

    1. Sridhar Katakam Avatar

      How do we call a function in the middle of text inside a Text element?

      1. Asbjørn Pettersen Avatar
        Asbjørn Pettersen

        No, not directly, but instead og the «sk_current_year()» function

        1. Sridhar Katakam Avatar

          Yes. We can inside a Code Block element.

Leave a Reply to Sridhar Katakam Cancel reply

Your email address will not be published. Required fields are marked *