- This topic has 5 replies, 3 voices, and was last updated 3 years, 1 month ago by
Tom.
-
AuthorPosts
-
December 30, 2019 at 6:37 am #1117388
S.A.
Hi there,
I use an element hook to import new posts. The content I am importing is a shortcode which looks like:
[jsoncontentimporterpro url=yes url=https://someapiwithakey123abc&iata_code=<cf_wpcf-arrival-airport\> value&type=something]
But after importing the content it shows:
[jsoncontentimporterpro url=yes url=https://someapiwithakey123abc&iata_code= value&type=something]
I don’t execute the shortcode in the element. Only the PHP. And when I run the same script outside of the element it imports the correct format/text.
Any idea how I can fix this?
December 30, 2019 at 7:11 am #1117554David
StaffCustomer SupportHi there,
you will need to check Execute Shortcode for it to work in a Hook Element.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 30, 2019 at 7:20 am #1117568S.A.
Tried it, but the script doesn’t execute and I see the following error message:
Parse error: syntax error, unexpected 'alert' (T_STRING), expecting ')' in /www/wp-content/plugins/gp-premium 2/elements/class-hooks.php(180) : eval()'d code on line 71
December 30, 2019 at 7:22 am #1117569David
StaffCustomer SupportTry the
do_shortcode
function:https://developer.wordpress.org/reference/functions/do_shortcode/#user-contributed-notes
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 30, 2019 at 8:38 am #1117615S.A.
Added the function, but in that case it already executes the shortcode and places the result in the post. It should place the shortcode in the post (without the strange formatting) so the shortcode can execute when a user visit the post. The result of the shortcode is dynamic.
December 30, 2019 at 9:57 am #1117676Tom
Lead DeveloperLead DeveloperNot too sure what you mean there – I assume you want the shortcode to execute on the frontend so something displays for the user?
If so, have you tried this?:
<?php echo do_shortcode( '[jsoncontentimporterpro url=yes url=https://someapiwithakey123abc&iata_code=<cf_wpcf-arrival-airport\> value&type=something]' ); ?>
Then Execute PHP.
If that doesn’t work, it’s possible that the formatting of the shortcode is throwing things off. You might need to use a manual hook, instead:
add_action( 'generate_before_content', function() { echo do_shortcode( '[jsoncontentimporterpro url=yes url=https://someapiwithakey123abc&iata_code=<cf_wpcf-arrival-airport\> value&type=something]' ); } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.