0

I have a simple shortcode to show post_type slug when I needed.

when using shortcode in text widget:

-in "post_type single page" it's working

-But in same sidebar and same widget in "post_type archive page" returns nothing.

the strange thing is the same shortcode is working when using do_shortcode function even in the "post_type archive page" template but in text widget has no success.

function post_type_slug()
{
    $string = get_post_type();

    return $string;
}
add_shortcode('pts', 'post_type_slug');

1 Answer 1

0

unfortunately I have no success with get_post_type() but get_queried_object() helped.

I changed the code to:

function post_type_slug()
{
    $post_type = get_queried_object();
    $post_type = $post_type->rewrite['slug'];

    return $post_type;
}
add_shortcode('pts', 'post_type_slug');

and it's working in text widget now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.