[Resolved] Shortcodes in elements?

Home Forums Support [Resolved] Shortcodes in elements?

Home Forums Support Shortcodes in elements?

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #776492
    Matthew

    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.

    #776706
    Leo
    Staff
    Customer Support

    Hi 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.

    #776775
    Matthew

    Okay, 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?

    #777114
    Matthew

    I 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.

    #777304
    Leo
    Staff
    Customer Support

    Glad you figured out!

    #935266
    Tom

    Are 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.

    #935521
    David
    Staff
    Customer Support

    Hi 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.

    #935680
    Tom

    Thank you!

    Where can I find said “Execute Shortcode” checkbox?

    #935714
    David
    Staff
    Customer Support
    #935769
    Tom

    So shortcodes cannot run in Elements… only in Hooks?
    Your second answer contradicts your first answer.

    #935905
    David
    Staff
    Customer Support

    Header Elements – they are on by default, no checkbox required.
    Hook Elements – require the checkbox to be activated – its an extra layer of security.

    #935922
    Tom

    That 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?

    #935927
    David
    Staff
    Customer Support

    Check 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.

    #935944
    Tom

    I 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.

    #935988
    David
    Staff
    Customer Support

    Would 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:

    https://generatepress.com/contact/

Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.