[Resolved] Add element as SHort Code or insert to page?

Home Forums Support [Resolved] Add element as SHort Code or insert to page?

Home Forums Support Add element as SHort Code or insert to page?

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1052118
    Paul

    Hey,

    Ok… Having trouble inserting PHP into elementor… Created an element with…

    <?php echo date('F jS' , strtotime(' + 14 days')); ?>

    And want to insert in a specific spot on page… Any way to do this easy?

    [premium-date]

    should show the element… or a better way to do this would be better πŸ˜‰

    Please let me know.. Thanks!

    #1052149
    David
    Staff
    Customer Support

    Hi there,

    simplest way is to create a shortcode then you can add that to your content eg. this PHP snippet:

    function display_premium_date() {
        echo date('F jS' , strtotime(' + 14 days'));
    }
    add_shortcode('premium_date', 'display_premium_date');

    Will create the [premium_date] shorcode.

    Adding PHP:
    https://docs.generatepress.com/article/adding-php/

    #1052162
    Paul

    Hey,

    I added the php snippet to my functions.php file… and added the shortcode into elementor.. Didn’t show up.. See page. And.. cant say it enough David.. u da man!

    #1052165
    Paul

    wait..

    #1052167
    Paul

    nevermind… it works πŸ˜‰ I used [premium-date] instead of [premium_date]

    #1052169
    Paul

    Now I just have to figure out how to place within a sentence πŸ˜‰

    #1052178
    David
    Staff
    Customer Support

    haha – yeah sorry i used an underscore πŸ™‚
    Inside a sentence your would need to use a HTML Widget then you can include the shortcode – should work in elementor eg.

    <p>Some text [premium_date] around the premium date</p>

    #1052187
    Paul

    Hey,

    Ok.. peep the page for me please…

    The 1st section is a heading widget… used same code <p>Some text [premium_date] around the premium date</p>

    The 2nd section is a text editor widget.. using the same code <p>Some text [premium_date] around the premium date</p>

    1st section is showing the date at the top left page after the header…
    2nd section showing it above the paragraph..

    lol…. oh man..

    #1052188
    Paul

    3rd section…. is an HTML widget… added the date at the top with the 1st section…

    #1052192
    Paul
    #1052197
    Paul

    Thinking….

    I could just add the code within the php snippet… I will try that.

    #1052199
    David
    Staff
    Customer Support

    Try this for your shortcode:

    function display_premium_date() {
        ob_start();
        echo date('F jS' , strtotime(' + 14 days'));
        return ob_get_clean();
    }
    add_shortcode('premium_date', 'display_premium_date');
    #1052205
    Paul

    Ok.. was in the process of changing… but tried ur updated code… and wallaahhh πŸ˜‰ Thanks David!

    #1052206
    David
    Staff
    Customer Support

    You’re welcome

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.