Archived topic
Strange text format after importing content using elements>>hooks
5 replies · Started by S.A. on December 30, 2019
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?
Hi there,
you will need to check Execute Shortcode for it to work in a Hook Element.
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
Try the do_shortcode function:
https://developer.wordpress.org/reference/functions/do_shortcode/#user-contributed-notes
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.
Not 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]' );
} );