• Hello guys, what’s up!

    I am writing my first shortcode and although it’s working great basically, the $content part is behaving rather weird.

    Whenever called without content and without attributes, like this:
    [zr_id]
    the shortcode should return the currently logged-in user id,
    which however does not happen, since is_null($content) fails to return ‘true’…

    Here is the code:

    function zr_id_func( $atts, $content = null ) {
    	extract(shortcode_atts(array('zkid' => null), $atts));
    
    	if ( is_null($content) ) {
    		if ( isset($zkid) )
    			$user_ID = $zkid;
    		else
    			global $user_ID;
    	}
    	else {
    		//return 'not null?';
    		$user_ID = do_shortcode($content);
    	}
    	return get_field('zr_username', 'user_' . $user_ID);
    }
    add_shortcode( 'zr_id', 'zr_id_func' );

    Any ideas? Even tried trimming $content like this:
    if ( is_null($content) ) {...

    Without any success – same result!

    Your help will be much appreciated. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shortcode $content bahaving bad!’ is closed to new replies.