• Resolved La M

    (@lady_moocher)


    Hi

    I’d like to hide part of the main body of my template from visitors who are not logged in. So I mean in the same way that the link for “Edit this entry” appears on page when you log in, I would like an extra form to be available only to admin members.

    Can somebody advise how I would do this please?

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php if ( !$user_ID ) : ?>
        Hide me
    <?php else : ?>
        show me
    <?php endif; ?>

    You can also use is_admin () function, depending on what you want exactly.

    <?php if ( !is_admin() ) : ?>
        Hide me
    <?php else : ?>
        show me
    <?php endif; ?>

    Other possibilities , using current_user_can() function :

    if current_user_can( 'edit_posts' )
    if current_user_can( 'read_posts' )

    and so on.

    Thread Starter La M

    (@lady_moocher)

    Thanks roya

    To explain exactly what I’m trying to do – I have a page with a list of links on it to archived newsletters for the public to download.

    I would like there to be a form on this page which allows the administrators to log into a separate site (I have the form code for this bit), but I only want this to be visible to the administrator and editors when they’re logged in. So which approach would be best?

    The first solution (using $user_ID) will allow all logged in users (subscribers, administrators, authors, contributors, editors) to use the form.
    The second, using is_admin() will allow only administrators to use your form.
    So, if you want to allow only the administrators to log into a separate site I think that the second one is better (using is_admin()).

    Thread Starter La M

    (@lady_moocher)

    Is there anyway t use the first one but extend the access to editors as well?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide part of a template from public’ is closed to new replies.