Site logo

Archived topic

How to get slug inside a Element Header

20 replies · Started by Kir29 LLC on January 13, 2019

Viewing posts 16–21 of 21

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.

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.

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

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!

Glad we could help :)

This archived topic is closed to new replies.