[Support request] Dynamic Shortcode with Custom Field

Home Forums Support [Support request] Dynamic Shortcode with Custom Field

Home Forums Support Dynamic Shortcode with Custom Field

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1655581
    Timo de Vries

    Hi,

    I am trying to populate a shortcode with a custom field. I tried using the hook element, activated “Execute Shortcodes” and “Execute PHP” and added: [CP_CALCULATED_FIELDS id=”<?php the_field(‘testid’); ?>”]
    but had no luck. Can you help me figuring out on how to achieve that?

    At the same time the shortcode should be inserted in one of my containers. This seems to not be possible with hooks, any solutions on that?

    All in all I have the same layout for all of my posts. I would like to create that layout with the “Blocks” Element, fill it with some styles and containers and add a shortcode ([CP_CALCULATED_FIELDS id=”XXX”] where the XXX should be populated with a custom field (no matter if I use ACF or default post meta fields).

    Thanks

    #1655952
    David
    Staff
    Customer Support

    Hi there,

    where does the shortcode come from ? Did you create it or is it from another plugin ?

    #1655959
    Timo de Vries
    #1656086
    David
    Staff
    Customer Support

    For the hook element you could something like this for example:

    $itemid = get_field( "item_id" );
    $shortcode = '[the_shortcode id="'.$itemid.'"]';
    echo do_shortcode($shortcode);

    For the Block Element its a bit trickier as your sort of asking for a shortcode within a shortcode as Blocks won’t accept PHP.

    I would suggest asking the developer if they have a PHP function for calling the content instead of a shortcode.

    Then you could create your own shortcode to output that function.

    #1656187
    Timo de Vries

    Hi David,
    thanks for the snipppet!
    I contacted the developer and there doesn’t seem a function for calling the content of the shortcode.

    As my block layout is pretty basic, I might just use it in the hook. The plain HTML looks like that:

    <section class="gb-container gb-container-db2ef2d5 alignwide">
    <div class="gb-inside-container">
    <div class="gb-container gb-container-7b4c3815">
    <div class="gb-inside-container">
    SHORTCODE OUTPUT
    </div>
    </div>
    </div>
    </section>

    I assume the gb-container-ID is used to apply the custom styles. Can I just omit the individual ID and assign my own class like
    <div class="gb-container gb-container-testclass">
    or do I need it for anything?

    #1656380
    David
    Staff
    Customer Support

    Are you wanting to use styles from a GB Block ?

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