[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
    Wes Peery

    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
    Wes Peery

    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
    Wes Peery

    wait..

    #1052167
    Wes Peery

    nevermind… it works 😉 I used [premium-date] instead of [premium_date]

    #1052169
    Wes Peery

    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
    Wes Peery

    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
    Wes Peery

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

    #1052192
    Wes Peery
    #1052197
    Wes Peery

    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
    Wes Peery

    Ok.. was in the process of changing… but tried ur updated code… and wallaahhh 😉 Thanks David!

    #1052206
    David
    Staff
    Customer Support
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.