- This topic has 22 replies, 2 voices, and was last updated 3 years, 7 months ago by Leo.
-
AuthorPosts
-
January 8, 2019 at 9:30 am #776492Matthew
I have ultimate shortcode plugin installed and I have the following in a GP element:
<?php $out = 'hello'; echo do_shortcode('[su_spoiler title="Spoiler title" open="no" style="default" icon="plus" anchor="" class=""]'.$out.'[/su_spoiler]'); ?>
On output, the shortcode works (a click-expand thing), but the content inside the shortcode literally writes (including single quotes)
‘.$out.’
on the display… why is this happening? I obviously have both shortcode and execute php boxes checked.
January 8, 2019 at 4:34 pm #776706LeoStaffCustomer SupportHi there,
Hmm I’m not sure if you can use PHP between the shortcode like that.
Can you check with Ultimate Shortcode’s support to see if this is indeed the correct usage?
Hooks don’t do anything special to your code – it just displays whatever you have in there.
I would assume there is either a syntax error or you can’t use it like that. The plugin support should be able to tell you that.
January 8, 2019 at 6:53 pm #776775MatthewOkay, I looked into it more and it’s weird… if you put just what I pasted into an element, it spits out “hello” like it should. But if you add a function call, it doesn’t.
For example…
The following renders the shortcode function but prints ‘$out’ literally.
<?php $postcat = get_the_category( $query->post->ID); $out= 'hello'; echo do_shortcode('[su_spoiler title="Spoiler title" open="no" style="default" icon="plus"]'.$out.'[/su_spoiler]'); ?>
The following renders the shortcode function but prints ‘$out’ literally.
<?php $query = new WP_Query(array('tag_id'=>99)); $out= 'hello'; echo do_shortcode('[su_spoiler title="Spoiler title" open="no" style="default" icon="plus"]'.$out.'[/su_spoiler]'); ?>
The following renders the shortcode function and prints hello inside.
<?php $out= 'hello'; echo do_shortcode('[su_spoiler title="Spoiler title" open="no" style="default" icon="plus"]'.$out.'[/su_spoiler]'); ?>
Do you have any idea why calling a function inside of an element like this causes do_shortcode to break?
January 9, 2019 at 6:22 am #777114MatthewI solved it. I don’t understand why it works, but it works.
<?php $query = new WP_Query(array('tag_id'=>99)); ?> <?php $out= 'hello'; echo do_shortcode('[su_spoiler title="Spoiler title" open="no" style="default" icon="plus"]'.$out.'[/su_spoiler]'); ?>
By separating the two using PHP opening and closing tags, it solves the issue and prints “hello” for $out. Totally weird.
January 9, 2019 at 7:32 am #777304LeoStaffCustomer SupportGlad you figured out!
June 19, 2019 at 6:08 pm #935266TomAre shortcode allowed in Elements? I have a shortcode for my real estate search module. It works in normal page sections, but in my home page element it just types out {wp-realty searchpage} as text.
June 20, 2019 at 2:08 am #935521DavidStaffCustomer SupportHi there,
yes the Header Element supports shortcodes.
The hook element does also but you need to check the Execute Shortcodes box for them to work.June 20, 2019 at 5:24 am #935680TomThank you!
Where can I find said “Execute Shortcode” checkbox?
June 20, 2019 at 6:00 am #935714DavidStaffCustomer SupportIts only in the Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/#settings
June 20, 2019 at 6:42 am #935769TomSo shortcodes cannot run in Elements… only in Hooks?
Your second answer contradicts your first answer.June 20, 2019 at 6:52 am #935905DavidStaffCustomer SupportHeader Elements – they are on by default, no checkbox required.
Hook Elements – require the checkbox to be activated – its an extra layer of security.June 20, 2019 at 7:06 am #935922TomThat is my problem. The Element is simply displaying the shortcode “{ wp-realty searchpage }” as text.
The shortcode is not being parsed by the Element. How can I troubleshoot this issue?
June 20, 2019 at 7:11 am #935927DavidStaffCustomer SupportCheck your shortcode they should look like:
[shortcode]
instead of{shortcode}
If still an issue test the shortcode in the page editor to eliminate a problem with the shortcode itself.
June 20, 2019 at 7:20 am #935944TomI tried that. The Element displays “[wp-realty searchpage]” as text.
I am using the shortcode on several pages without issue. It is only in the Element that it does not display correctly.
https://saltlakecityrealty.net/
Thank you for helping me with this issue.
June 20, 2019 at 7:57 am #935988DavidStaffCustomer SupportWould you be able to provide us with temporary admin access so i can take a look?
You can send login details, with the URL to this topic for tracking to the Account Issue form:
-
AuthorPosts
- You must be logged in to reply to this topic.