The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Shortcode inside widget (2 posts)

  1. Mickey Kay
    Posted 3 years ago #

    Hi there,

    I've created a shortcode I'd like to use in a widget, however it's behaving a bit wonky and I can't figure it out. Here's the code in functions.php:

    function related_content( $atts ) {
    	return get_the_ID();
    add_shortcode('related-content', 'related_content');

    The problem is that if I embed this shortcode in a page, it does indeed spit out the correct ID of that page. However if I embed the code in a sidebar widget, it spits out a different ID entirely (it happens to be the ID of my blog page in this case). Any thoughts on why this is happening? Is there something about the context in which the shortcode is being called inside a widget? Any ideas?

    - Mickey

  2. MangoThemes
    Posted 3 years ago #

    Try to add this into functions.php:

    define('FILTERPRIORITY', 10);
    add_filter('the_content', 'do_shortcode', FILTERPRIORITY);
    add_filter('widget_text', 'do_shortcode', FILTERPRIORITY);

    Should help :)

Topic Closed

This topic has been closed to new replies.

About this Topic