[Resolved] How to get slug inside a Element Header

Home Forums Support [Resolved] How to get slug inside a Element Header

Home Forums Support How to get slug inside a Element Header

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #783803
    Kir29 LLC

    Hi Tom,

    I though about your answer and changed the PHP code with this one:

    add_shortcode( ‘slider-post_slug’, function() {
    global $post;

    if ( is_object( $post ) ) {
    return ‘[smartslider3 alias=”slider-‘ . $post->post_name . ‘”]’;
    }
    } );

    The new PHP code seems to to be working as returning what I need getting an output like this:

    [smartslider3 alias=”slider-the-authentic-madrid-tapas-tour”]

    The problem I’m facing now is that I don’t really know how to add the call to my slider-post_slug into the my Header Element.

    Do you know how could that be done?

    Thanks

    PS: Sorry, I’m not sure if I’m going in loops here.

    #784123
    Tom
    Lead Developer
    Lead Developer

    Wonder if you could do this:

    add_shortcode( 'slider-post_slug', function() {
        global $post;
    
        if ( is_object( $post ) ) {
            return do_shortcode( '[smartslider3 alias="slider-' . $post->post_name . '"]' );
        }
    } );

    Not 100% sure it will work, but it’s worth a shot.

    #784131
    Kir29 LLC

    Hi Tom,

    Not sure what that is to be honest.

    Where do I paste that code? In the heather emement or in my php?

    Sorry I’m confused now what that would do.

    Thanks

    #784134
    Tom
    Lead Developer
    Lead Developer

    That would be added in your PHP: https://docs.generatepress.com/article/adding-php/

    Then you’d use the shortcode in your Header Element: [slider-post_slug]

    #784494
    Kir29 LLC

    Hi Tom,

    It worked!!!

    I’ve added your latest PHP code suggested to my Code Snipper:

    add_shortcode( ‘slider-post_slug’, function() {
    global $post;

    if ( is_object( $post ) ) {
    return do_shortcode( ‘[smartslider3 alias=”slider-‘ . $post->post_name . ‘”]’ );
    }
    } );

    And then added the following shortcode suggested to my Header Element:

    [slider-post_slug]

    I’ve tested with multiple post and it works. I’m able to dynamically build a shortcode that contains my post slug as part of the name.

    Fantastic support Tom & David.

    Thank you!

    #784790
    Tom
    Lead Developer
    Lead Developer

    Glad we could help 🙂

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