Archived topic
Add element as SHort Code or insert to page?
13 replies · Started by Peery on November 3, 2019
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!
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/
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!
wait..
nevermind... it works ;) I used [premium-date] instead of [premium_date]
Now I just have to figure out how to place within a sentence ;)
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>
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..
3rd section.... is an HTML widget... added the date at the top with the 1st section...
Thinking....
I could just add the code within the php snippet... I will try that.
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');
Ok.. was in the process of changing... but tried ur updated code... and wallaahhh ;) Thanks David!
You're welcome