Forums

Can I add a "new post" link on public site when logged in? (21 posts)

  1. brianlees
    Member
    Posted 7 years ago #

    I would like to add a link to the write post form on the public site that will display when I am logged in so I don't have to go to the admin site and then go to the new post form. I know, I know, its a few clicks, but it will also be easier for my wife.

    Is there a plugin out there for this or is it easy to add to the templates?

  2. oriecat
    Member
    Posted 7 years ago #

    Just manually add a link where you want it to appear.

    http://yoursite/wp-admin/post.php

  3. brianlees
    Member
    Posted 7 years ago #

    Thanks. But, how do I get it to only show up when logged in?

  4. oriecat
    Member
    Posted 7 years ago #

    Oooh I missed that part. :) Hmmm....

  5. oriecat
    Member
    Posted 7 years ago #

    Ok, here's a thought... I don't know how to make it a plugin, maybe somebody smarter could do that, but you could hack the function... the wp_register function shows either the register button or the site admin button depending upon if it's a logged in registered user. So you could change the function to point to the post page instead of the dashboard.

    In wp-includes/template-functions-general.php find wp_register. Then change

    $link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;

    To say:

    $link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/post.php">' . __('Make a New Post') . '</a>' . $after;

    I tried just adding the second line to see if it would show both, but that didn't work. Maybe it's just missing something to make it do that.

  6. brianlees
    Member
    Posted 7 years ago #

    Hmm...my site is pretty clean and only has two users, so I don't have the register displaying. I just have a login link in the footer. I appriciate the help, but I would prefer to not hack it so I don't have to worry as much with upgrades in the future. I'm just supprised there is no tag that can wrap code to display depending on your login status. I couldn't find anything in the CODEX after a quick glance, but I might have missed it.

  7. IanD
    Member
    Posted 7 years ago #

    Maybe a reworking of the 'Logged in as' section of comments.php?

    <?php if ( $user_ID ) : ?>
    <a href="<?php echo get_option("siteurl"); ?>/wp-admin/post.php">Post new article.</a> <a href="<?php echo get_option("siteurl"); ?>/wp-login.php?action=logout" title="<?php _e("Log out of this account") ?>">Logout &raquo;</a>
    <?php endif; ?>

    Seems to work?.. I also left the 'logout' option, thought it might be useful.

  8. oriecat
    Member
    Posted 7 years ago #

    Good thinking, Ian, but where did you put that to make it work? I put it in my sidebar a couple places and I never got anything to show up.

  9. IanD
    Member
    Posted 7 years ago #

    I just threw it between <li></li> tags in one of my sidebar lists. It was there when I was logged in, so I logged out and it all disapeared.

  10. brianlees
    Member
    Posted 7 years ago #

    Hmm...I added that code to my footer and nothing showed up. So, since this there doesn't seem to be an immediate answer, I guess there is no wordpress function or tag to wrap around code? That seems like a huge oversite, doesn't it? I mean, I know that this is only at v1.5...but still. I MUST be missing something obvious.

  11. moshu
    Member
    Posted 7 years ago #

    I have this code in more themes:
    <?php edit_post_link(__('Edit This')); ?>
    and it shows up only when I am logged in.

    EDIT. Oops... I misread the original post. This does not take you to the write new post admin panel. Sorry.

  12. oriecat
    Member
    Posted 7 years ago #

    Brian, why not just create a bookmark for the post page?

  13. Kafkaesqui
    Moderator
    Posted 7 years ago #

    Put this where you want the link to appear (though you may need to change the url for post.php):

    <?php
    global $user_login;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    <a href="/wp-admin/post.php">New Post</a>
    <?php endif; ?>

  14. brianlees
    Member
    Posted 7 years ago #

    That worked. Just needed to remove the leading "/" from the href.

  15. InFnit
    Member
    Posted 6 years ago #

    What if I want to display something when the person is not logged in? Like
    Not Registered? Register Today!

    PS: I want to do this because I want to remove Site Admin link as I am making links like Submit and Article and Edit my Profile.

  16. Kafkaesqui
    Moderator
    Posted 6 years ago #

    Mod of example above to provide that:

    <?php
    global $user_login;
    get_currentuserinfo();
    if ($user_login) :
    ?>
    <a href="wp-admin/post.php">New Post</a>
    <?php else : ?>
    Not registered? Register today!
    <?php wp_register('', ''); ?>
    <?php endif; ?>

    May need some HTML customizing. Info on wp_register():

    http://codex.wordpress.org/Template_Tags/wp_register

  17. InFnit
    Member
    Posted 6 years ago #

    I asked someone on MSN and they said this:
    <?php
    global $user_login;
    get_currentuserinfo();
    if ($user_login){
    echo '<a href="wp-admin/">Dashboard</a><br />
    <a href="wp-admin/profile.php">Edit my Profile</a><br />
    <a href="wp-admin/post.php">Submit an Article</a><br />'
    ;
    }
    else {
    echo '<a href="wp-register.php">Not Registered? Click here!</a>';
    }
    ?>

  18. Kafkaesqui
    Moderator
    Posted 6 years ago #

    Effectively the same. However, yours does let you customize the register link text by linking to wp-register.php manually.

  19. LoneBoat
    Member
    Posted 6 years ago #

    <?php if (isset($user_level)) {?>
    <li><a href="#">Howdy <?php echo $user_identity; ?>!</a></li>
    <li><a href='http://timskoch.com/wp-admin/post.php'>New Post</a></li>
    <?php } ?>

    I just implemented the above code in my site, and it works fine. But I have one problem: If I click the "New post" link, I'm asked to re-enter my login. Any ideas how to fix that?

  20. LoneBoat
    Member
    Posted 6 years ago #

    Oops, I found an easy fix: Use a relative link:

    <?php if (isset($user_level)) {?>
    <li><a href="#">Howdy <?php echo $user_identity; ?>!</a></li>
    <li><a href=/wp-admin/post.php'>New Post</a></li>
    <?php } ?>

    Duh...

  21. radagast
    Member
    Posted 5 years ago #

    or how about this:

    <?php if (current_user_can('publish_posts')) { ?>
    whatever whatever whatever
    <?php } ?>

    here's a better explanation:
    http://boren.nu/archives/2005/12/01/whats-new-in-20-roles-and-capabilities/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.