Floating Admin Button
This pure CSS utility cleverly uses a checkmark to control the toggle state of its menu items. Though not quite A11y-friendly enough to show to site visitors, this floating toolkit with add and edit post actions is handy for blog management!
Based on Mark Eriksson’s Pure CSS FAB
<!--Floating Admin Buttons-->
<!-- 1: User role check -->
<If user_role includes value="administrator,editor,author">
<!-- 2: Edit post check-->
<Set logic=edit_post_check all=true>
<If singular="post" type="post,gallery">true<Else />false</If>
<If user_field=name is value="{Field author_name}">true<Else />false</If>
</Set>
<!--Buttons-->
<div class="fab-admin">
<input type="checkbox" name="fab-admin-toggle" class="fab-admin-toggle" />
<a class="fab-admin-button" href="#!">
<i class="fa fa-cog"></i>
</a>
<div class="fab-admin-buttons">
<!--New Post Button-->
<a href="/wp-admin/post-new.php" title="New Post">
<i class="fa-solid fa-newspaper"></i>
</a>
<!-- 3. New Gallery Button-->
<a href="/wp-admin/post-new.php?post_type=gallery" title="New Gallery">
<i class="fa-solid fa-images"></i>
</a>
<!-- 4. Edit Post/Gallery Button-->
<If logic=edit_post_check>
<If singular="post" type="post">
<a href="{Field edit_url}" title="Edit Post">
<i class="fa-solid fa-pen-to-square"></i>
</a>
<Else if singular="post" type="gallery" />
<a href="{Field edit_url}" title="Edit Gallery">
<i class="fa-solid fa-pen-to-square"></i>
</a>
</If>
</If>
</div>
</div>
</If>
This snippet requires Font Awesome Classic support, or you can replace the icons with your own.
- This If tag wraps the entire template, only displaying the buttons if the current user has a role of administrator, editor, or author
- This logic variable checks if the current user is the post author, and whether the current post type is one of those supported. It’s used to conditionally display the edit actions when appropriate.
- This “New Gallery” button adds a new post to the
gallery
custom post type. Remove it or replace the post type slug with your own! - The edit buttons use a conditional check to determine the current post type, in order to customize the button icons and classnames. You’ll likely want to adjust this logic your own post type, or remove it entirely
/* Floating Admin Buttons */
.fab-admin {
position: fixed;
bottom: 35px;
right: 35px;
z-index: 999;
}
.fab-admin-button {
height: 60px;
width: 60px;
background-color: rgba(67, 83, 143, .8);
border-radius: 50%;
display: block;
color: #ffffff;
text-align: center;
position: relative;
z-index: 1;
}
.fab-admin-button i {
font-size: 30px;
}
.fab-admin-buttons {
position: absolute;
width: 100%;
bottom: 120%;
text-align: center;
}
.fab-admin-buttons a {
display: block;
width: 45px;
height: 45px;
border-radius: 50%;
text-decoration: none;
margin: 10px auto 0;
line-height: 1.15;
color: #fff;
opacity: 0;
visibility: hidden;
position: relative;
box-shadow: 0 0 5px 1px rgba(51, 51, 51, .3);
}
.fab-admin-buttons a:hover {
transform: scale(1.05);
}
.fab-admin-buttons a:nth-child(1) {
background-color: #03a9f4;
transition: opacity .2s ease-in-out .3s, transform .15s ease-in-out;
}
.fab-admin-buttons a:nth-child(2) {
background-color: #c003f4;
transition: opacity .2s ease-in-out .25s, transform .15s ease-in-out;
}
.fab-admin-buttons a:nth-child(3) {
background-color: #00b41e;
transition: opacity .2s ease-in-out .2s, transform .15s ease-in-out;
}
.fab-admin-buttons a:nth-child(4) {
background-color: #4CAF50;
transition: opacity .2s ease-in-out .15s, transform .15s ease-in-out;
}
.fab-admin a i {
color: #ffffff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.fab-admin-toggle {
-webkit-appearance: none;
position: absolute;
border-radius: 50%;
top: 0;
left: 0;
margin: 0;
width: 100%;
height: 100%;
cursor: pointer;
background-color: transparent;
border: none;
outline: none;
z-index: 2;
transition: box-shadow .2s ease-in-out;
box-shadow: 0 3px 5px 1px rgba(51, 51, 51, .3);
}
.fab-admin-toggle:hover {
box-shadow: 0 3px 6px 2px rgba(51, 51, 51, .3);
}
.fab-admin-toggle:checked~.fab-admin-buttons a {
opacity: 1;
visibility: visible;
}