@mdo

Powered by Fusion

Add a quick post link to your WordPress blog

New post

WordPress’s conditional tags are pretty freaking awesome. They came to my rescue when I wanted to add a quick “new post” link to my blog pages for when I’m logged in (which is nearly all the time). Here’s a quick block of code to help you do the same:

<?php if (is_user_logged_in()) { ?>
  <a href="/wp-admin/post-new.php" id="newPost">+</a>
<?php } ?>

That’s all you need on the PHP side; just add it to the end of your footer.php right before the wp_footer(). To style it, here’s a quick bit of CSS:

a#newPost {
  position: fixed;
  top: 0;
  right: 40px;
  background: rgba(0,0,0,.25);
  .borderBottomRadius(3px);
  font-size: 40px;
  font-weight: bolder;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,.25);
  padding: 5px 15px 10px;
}

And that’s it—enjoy!


Questions?

Have a question about this post, Bootstrap, GitHub, or anything else? Ask away on Twitter or in my AMA repo.