• I have a plugin I’ve created and am using a shortcode. for some reason, I cannot get the shortcode to work.

    if(!class_exists('FE_SuperFiction'))
    {
    	class FE_SuperFiction {
    		function __construct() {
    			/** bunch of other code here **/
    			add_shortcode('fanficme_fanfiction', array(&$this, 'FeFiction_Site_Display'));		}
    			/** bunch of other code here **/
    		}
    		function FeFiction_Site_Display() {
    			/** bunch of code here **/
    			echo __LINE__.' - test ';
    			/** bunch of code here **/
    		}
    	}
    }

    I then add a page with the content being: [fanficme_fanfiction]

    I then visit that page and it still shows [fanficme_fanfiction] instead of the output I expect (in the above case, the line number and the text ” – test”.

    I even went into wp-includes/shortcodes.php and confirmed that my shortcode is included.

    From the output of printing $output contained in do_shortcode:

    (.?)\[(embed)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)
    (.?)\[(wp_caption|caption|gallery|embed|fanficme_fanfiction|ratings)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Upstreet Media

    (@phxvyper)

    I’ve been digging around more and I’m still at a loss as to why the shortcode is not working :/

    Thread Starter Upstreet Media

    (@phxvyper)

    When WP is executing the do_shortcode, for some reason $content is empty, which explains why it isn’t executing my function.

    BUT, if $content is empty, how is it that when the page loads, my shortcode is displaying????

    Something isn’t right here.

    function do_shortcode($content) {
    	global $shortcode_tags;
    
    	if (empty($shortcode_tags) || !is_array($shortcode_tags))
    		return $content;
    
    	$pattern = get_shortcode_regex();
    	return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘shortcode not working’ is closed to new replies.