• Resolved 0cg0

    (@0cg0)


    Hi Tobias and thanks for your awesome plugin.
    I have a similar problem with this post from @ akshat007 https://ww.wp.xz.cn/support/topic/shortcode-not-working-when-fetching-post-content-via-ajax/

    Basically I’m trying to populate a custom field on the Woocommerce product page with data from a record from a Tablepress table.
    I only need to display some cells, my shortcode is this: [xxx_table_cell id = 123 column = 2 /] [xxx_table_cell id = 123 column = 3 /] […].

    If I insert the schortcode on the product page in WP (in description or with ACF) the shortcode works perfectly in the frontend, but if I call it from function.php it is displayed as code ([xxx_table_cell id = 123…).

    Basically what I’m trying to do is populate the $test variable with the table data and then initialize the custom input field like this:

    printf(“<div class=’yyy-custom-field-wrapper’><label for=’yyy-title-field’>%s</label><input type=‘text’ id=’yyy-title-field’ name=’yyy-title-field’ value=’$test’ ></div>”, esc_html( $title ).

    But “value” returns the shortcode as code and not the table data.

    I hope someone can help me.
    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Most likely, you will just need a line like

    $test = do_shortcode( $test );
    

    right before your printf line.
    This line would then actually evaluate the Shortcodes.

    (I would also recommend adding second line

    $test = esc_attr( $test );
    

    for enhanced security and a reduced risk of having broken HTML code.)

    Regards,
    Tobias

    Thread Starter 0cg0

    (@0cg0)

    Tobias,
    works great.
    I was taking a much more convoluted approach!
    Your plugin deserves 5 stars and you 6 for availability!
    Thanks again!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘The shortcode does not work in the frontend when called from the code.’ is closed to new replies.