• Resolved owh

    (@owh)


    Greetings to fellow WordPress users.

    I created a simple shortcode with the following function to hide part of the content in a post/page.

    if ( is_user_logged_in() )
    return $content;

    It works in doing that. The relevant content only shows when I am logged in.

    However, the gallery shortcode doesn’t work. It appears as text, for example:

    [gallery type="rectangular" ids="14867,14868,14869,14870,14871"]

    I tried to place another shortcode within the hidden content, and the same problem appeared.

    Anyone know how to make the gallery (or shortcode to run, in general) show up as gallery (instead of the shortcode in text)?

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • J M

    (@hiphopinenglish)

    You must be editing a theme Template I guess. Shortcodes placed in templates won’t work by default. You need to wrap your shoprtcode in PHP:

    <?php echo do_shortcode("[gallery type="rectangular" ids="14867,14868,14869,14870,14871"]"); ?>

    Thread Starter owh

    (@owh)

    Thanks a lot for the reply. My description must be unclear. I shall explain again.

    I created a shortcode, wrapped in php, as [memberonly]. This code is obtained from internet.

    add_shortcode( 'memberonly', 'member_only' );
    
    function member_only( $atts, $content = null ) {
    	 if (  !is_user_logged_in()  )
    		return $content;
    	return '';
    }

    When I use it to hide some content, it does the job.

    [memberonly]some content in here[/memberonly]

    However, if I have other shortcode in the content to hide, the shortcode is not “executed”. In my case, it was the [gallery].

    [memberonly]some text and then the [gallery ...][/memberonly]

    The above is show as in text only, i.e. the gallery is not displayed as image gallery.

    Any idea?

    J M

    (@hiphopinenglish)

    I can’t explain why for sure, but looking at this thread, you’ll need to add do_shortcode($content); into where you wrote your shortcode function.

    Thread Starter owh

    (@owh)

    Thank you very much! That works!

    Thread Starter owh

    (@owh)

    Forgot to mark as resolved …

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Showing content to members only – gallery not working’ is closed to new replies.