• Dear all.
    function get_post_title_shortcode( $atts ) {
    ? ? $atts = shortcode_atts( array(
    ? ? ? ? ‘id’ => get_the_ID(),
    ? ? ), $atts, ‘post_title’ );
    ? ? $post_title = get_the_title( $atts[‘id’] );
    ? ? return $post_title;
    }
    add_shortcode( ‘get_post_title’, ‘get_post_title_shortcode’ );

    I have create a function for short code it working well,
    but when I want it reader in INPUT as value Elementor HTML it not render
    EX: <input type=”hidden” mane=”tourCode” value=”[get_post_title]” />

    Anyone got this issue please share ideas?

    Thanks
    TY

Viewing 4 replies - 1 through 4 (of 4 total)
  • The condition for output is that an IP is available via get_the_ID(). Are you calling a single page? This will not work for archive pages, except perhaps in a loop. The context in which you insert the shortcode would therefore be very important.

    Moderator bcworkz

    (@bcworkz)

    Besides context being important in general, shortcodes within HTML tags will not be expanded as you are thinking they would be. In order to use a shortcode’s value within an input field, the shortcode would need to generate the entire tag within it’s expanded content. For example, [title_field] could be expanded into <input type="hidden" name="tourCode" value="A Post Title">, assuming the post’s title is available via code. Success still depends on context.

    Thread Starter Ty Chhoun

    (@tychhoun)

    Yes I use it in single post!
    In that page I have custom form submit, so I need input hidden field to keep current page or post title embed when I submit sent email, that I need
    <input type=”hidden” mane=”tourCode” value=”[get_post_title]” />

    Any better solution?

    Moderator bcworkz

    (@bcworkz)

    WP will not “see” shortcodes within a HTML tag. As I said earlier, your shortcode would need to generate the entire tag, not just the field’s value.

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