Custom shortcode not firing in template

WordPress
May 02, 2021 01:58:30
gci
Topics: 3
Messages: 5
Hi,

I have a custom shortcode that pulls ACF repeater fields and does timezone conversion, then prints in a list.
It works perfectly on the page, but does not fire in the pdf template.

I have tried in textarea and html object.

I have attached a screenshot of what the screenshot outputs.

Shortcode:
[dateau1]

Code:
function displayDateau1(){
if( have_rows('1_dates_&_times') ):

// Loop through rows.
while( have_rows('1_dates_&_times') ) : the_row();
// Load sub field value.
$sub_value = get_sub_field('date_&_time');
$utc_date = DateTime::createFromFormat('d/m/Y g:i a', $sub_value, new DateTimeZone('Australia/Sydney'));

$acst_date = clone $utc_date; // we don't want PHP's default pass object by reference here
$acst_date->setTimeZone(new DateTimeZone('America/New_York'));

echo '' . $utc_date->format('j M, Y g: i a') . '<br/>'; // UTC: 2011-04-27 2:45 AM
// echo '' . $acst_date->format('j M, Y g: i a'); // ACST: 2011-04-27 12:15 PM
endwhile;

// No value.
else :
// Do something...
endif;
}
add_shortcode('dateau1', 'displayDateau1');
May 02, 2021 08:53:29
E2Pdf
Topics: 7
Messages: 3617
Support
Hi,

There are 2 issues why shortcode not working.

1. E2Pdf Template has no global $post object so your shortcode can't get correctly data.
2. You are using "echo" in shortcode instead of "return".

To make it work:

1. We currently released an update which will allow using [id] as shortcode attribute so you can detect the Post ID for which it must be generated content so please update plugin to latest version (1.13.40 (Stable) or 1.14.13 (RC)).

2. Modify your PHP shortcode function to: https://codeshare.io/2KApqz. It has modification to detect "attribute" from where we will get the Post ID and replaced function which will output data via "return" and not with "echo". It must still work inside pages with same way without modification shortcode however it will be better to recheck.

3. Modify your shortcode inside E2Pdf Template to [dateau1 post_id="[id]"]

We remain at your service.

We would really appreciate your feedback at WordPress.org!
Get News and Updates
Our monthly newsletter keeps you in the loop, so you'll always be up to date with the latest news and updates about E2Pdf.
* You can update your email subscription preferences here.
All trademarks, service marks, trade names, product names, and logos appearing on this website are the property of their respective owners. The use of trademarks such as Formidable Forms®, Forminator Forms®, Gravity Forms®, JetFormBuilder®, WordPress®, WooCommerce®, WPForms® and others is solely for identification purposes (nominative use) and does not imply any affiliation, sponsorship, or endorsement by the respective trademark holders.
© 2017 - 2026, https://e2pdf.com

We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. By clicking "Accept Selected", you consent to use of selected cookies according to our Cookie Policy.