It’s common knowledge among the online community that WordPress is a very popular CMS. As such, you can always find cool tricks to make it unique or do things beyond its out-of-the box features. Check out these 6 cool hacks you can do to any WordPress site.
Highlight Blog Author Comments on Your Own Website
These little hacks will make it so any comments that you post on your blog will be highlighted in a color of your choosing. The exact configuration of code may vary depending on what kind of theme you have installed, but this should work for you, or at least point you in the right direction.
Look for the CSS that is applied to your author comments. If you are using the default WordPress commenting system, you will be looking for a class like .authcomment. Once you have found it, apply a hex color of your choice. You can find examples of hex colors here.
Your CSS should look something like this,
You will also want to define a class in comments.php like this,
$comment_class = (YOURUSERID == $comment->user_id) ? ‘comment-admin’ : ‘comment’;
Many WordPress templates come with their own 404 error pages. They are typically named 404.php. You can find this file in your theme folder. You should also be able to find it in your WP backend.
To modify your existing 404 page:
- Log into your backend.
- Open your theme editor or click “appearance” then “editor”
- Look for “404.php”
Open and edit the template by inserting your own text or code to display.
you should see code like this,
<?php get_header(); ?>
<h2 class=”center”>Insert some clever or funny text here that users can see when they hit a URL that does not have a page associated with it.</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Make All External Links Open in New Window by Default
To do this you will be searching for a file called link.htm; however, it may vary based on your theme. It can typically be found in the wp-includes directory and specifically at wp-includes/js/tinymce/themes/advanced/link.htm.
All you have to do is switch the order of the two lines of code below:
Now external links pasted into your posts should open in a new window.
Make A Custom Login Page for WP Backend
This is a nice little touch to brand your website even if you are the only one to see the login page. Depending on your version of WordPress, you will be looking for a file called login.css. In that file, you will be looking for background-color and h1 background image properties. The image will be located in your images folder and may be named logo-login.png or something similar.
You can also change the default link on the page from wordpress.org to your home page. If you want to change the login form, look for a hook like “form” somewhere in login.css. You can change anything you want from the fonts, input fields, links, etc.
Style Individual Posts
This hack allows you to style individual posts apart from the rest of the styling on your WordPress blog. You might want to make one post stand out from the rest such as announcements, or maybe a post that contains a special offer. You will be using this function:
<?php the_ID(); ?>
This function displays the numeric ID of the current post. It can also be used as a unique anchor identifier for each post, allowing you to style posts individually if you want to. The identifier might look like this inside of a post:
<h3 id=”post-<?php the_ID(); ?>”>Your Post Title</h3>
Entire posts are typically contained within divs and use of a div plus the function might look like this.
<div class=”post” id=”-<?php the_ID(); ?>”>post headline, post body, etc</div>
Find your specific post ID and insert style properties in style.css or applicable style sheet associated with your theme. It would look something like this.
font: ‘tahoma’, Arial;
Create a Page That Displays a Random Post
You will need to create a custom page in WordPress, and you can do this pretty easily from your backend interface. Just create a page and install the following code on it:
query_posts(array(‘orderby’ => ‘rand’, ‘showposts’ => 1));
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1><a href=”<?php the_permalink() ?>“><?php the_title(); ?></a></h1>
<?php the_content(); ?>
It is a loop that runs a query to tell WordPress to show random posts. Notice that the number attributed to ‘showposts’ is set to one. If you want to show more than one post on the page each time it is refreshed, increase that number.
There are tons of other hacks you can find around the web. WordPress is an extremely flexible CMS that you can customize in pretty much any way you want.
Are there any special tricks that you use with your WordPress blog that you would like to share?