Forums

[resolved] Hide part of a template from public (6 posts)

  1. lady_moocher
    Member
    Posted 3 years ago #

    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?

  2. roya khosravi
    Member
    Posted 3 years ago #

    <?php if ( !$user_ID ) : ?>
        Hide me
    <?php else : ?>
        show me
    <?php endif; ?>
  3. roya khosravi
    Member
    Posted 3 years ago #

    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.

  4. lady_moocher
    Member
    Posted 3 years ago #

    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?

  5. roya khosravi
    Member
    Posted 3 years ago #

    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()).

  6. lady_moocher
    Member
    Posted 3 years ago #

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

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic