QUICK TIP - WordPress tricks – The most useful tricks you should know

0 1,236,186
Most Useful .htaccess Tricks for WordPress | A&H Business Technology
Related posts

If you are one of the millions of people who use WordPress, this article will help you improve the appearance, functionality, and performance of your WordPress-powered websites. Each of these “WordPress tricks” is presented as clearly and succinctly as possible, including as many notes, instructions, and pointers as needed for successful implementation. Of course, keep in mind that we are only scratching the surface here.

So now, without further ado, here is my personal collection of easy-to-use, copy-&-paste WordPress tricks. Enjoy! 🙂

WordPress Shortcodes 

Save time by replacing your most commonly typed words and phrases with WordPress shortcodes. For example, if you are frequently typing your blog’s URL, you could place the following code your theme’s functions.php file:

Now whenever I write a post via “HTML-mode”, all I need to include my blog’s URL is type [myurl]. Works great in WordPress 2.5 or better.

Shortcodes with Attributes
To create a shortcode for links, we need to include the href attribute information as well as the anchor text for the link itself. We can do this by placing this function in your theme’s functions.php file:

Then, when creating a post, emulate the following format to include any links you wish:

[link href="https://ahbusinesstechnology.com/"]AH Business Technology[/link]

..which will output the following code:

<a href="https://ahbusinesstechnology.com/">AH Business Technology</a>

When the href attribute is removed from the shortcode, the default URL will be used. You may specify the default URL in the third line of the funtion (see comment).

Source: Digging into WordPress

Display WordPress Permalinks Outside of the Loop 

Normally, permalink display via the_permalink() requires the loop. To display permalinks outside of the loop, we may use either of the following methods:

Display Custom Message to Returning Visitors 

We can greet returning commentators with a custom message by extracting their information from the comment cookie left on their machine. Place the following code into the desired location in your theme and customize the message and markup to whatever you wish:

Display Recently Updated Posts and Pages 

Easily display a list of recently updated posts by placing the following code into the desired location in your theme:

Of course, customize the details as necessary and remember to set the number of posts via the $howMany variable.

Display Custom Content to Search Engine Visitors 

Display custom content to your search-engine traffic by placing the following code into your theme’s functions.php file:

After checking and editing the $SE array with the search-engine referrer information of your choice, place this next chunk of code into the desired display location in your theme file(s):

Add whatever content or code you wish to the specified area and enjoy targeted delivery to search-engine visitors only.

Source: Stephen Cronin

Display Last Modified Time and Date for Posts 

Display the “last-modified” time for your posts by placing this code anywhere within the loop:

Display Total Number of Trackbacks and Pingbacks 

Display the trackback/pingback count for each of your posts by first placing this code into your theme’s functions.php file:

And then call the number for display anywhere in your theme by adding this code to the desired location:

<?php comment_count(); ?>

Alternately, in WordPress 2.7, you may display the total number of comments by inserting this code directly into your comments.php template:

Edit the markup as desired. Will display “” or “”, depending on the number of comments.

Source: WPengineer.com

Display Recently Registered Users 

Quick and easy method for displaying a list of recently registered users. Place the following code directly into your theme, wherever you would like to display the list:

As-is, this code will spit out the five most recent registered users. This is easily changed to whatever number you wish by simply editing the number “5” in the first line.

List all of Your Site’s Posts 

If the default wp_get_archives(type=postbypost&limit=) function doesn’t provide enough flexibility to meet your needs, here is another way to list all of your site’s posts:

In place, that code will display a list of all of your blog’s posts. As a bonus, you may use any of the applicable parameters available to the get_posts() function to do just about anything you need with your posts list.

List WordPress User Information 

Here is an easy way to display flexible lists of your blog’s registered users’ information. In this example, we will list the first and last name of each user registered in the database:

The following variables may be used to display different types of user information and also to specify the sort order of the output list:

  • ID — User ID number
  • user_login — User Login name
  • user_nicename — nice version of login name
  • user_email — User Email Address
  • user_url — User Website URL
  • user_registered — User Registration date

To display any of these different types of user information, call it with $user->name_of_the_column anywhere within the function’s foreach() loop. To change the display order of the output, use any of the above as the value of the $szSort variable in the first line of the function. Note that strtolower and ucwords are used to ensure proper capitalization of the user names.

Display List of Scheduled Posts 

Got scheduled posts? Cool. Here’s how to display them to your readers:

Place that code in the desired location of your WordPress template and display a list of scheduled posts to your readers. To change the total number of displayed posts, edit the showposts=5 parameter to any number you wish. You may also use other parameters available to the WP_Query() function to further customize the output.

Display Private Posts to Logged-in Users 

To display private posts to your logged-in users, you will need to add a custom field called private for each private post and give it a value of true. Then, replace your default WordPress loop with the following:

This custom loop will check each post for the presence of a custom-field value of true. For each post that has this value, the loop will then check to see if the user is logged into your site. If the user is in fact logged in, the loop will display the private post(s). Public posts will be displayed as usual and regardless of whether the user is logged in or not.

Source: Digging into WordPress

Display Posts from Exactly One Year Ago 

Use this code to display posts that are exactly one year old:

To display posts from different days or different years, edit the two variables in the beginning of the method.

Custom CSS Styles for Recent Posts 

Use some custom CSS styles to highlight your recent posts. To do this, replace your existing loop with the following:

This new loop will check the date of each post and include a CSS class of new to any post published within the previous 24-hour time period. Once the new post class is included, you may style it with some custom CSS such as the following:

New WordPress-2.7 Comments Loop 

Due to the changes made to comment-related functions in WordPress 2.7, you will need to upgrade your comments template in order accomodate for the new functionality. The major changes are the new wp_list_comments() function and the next/previous_comments_link() functions. Here is an example comments.php loop to get you started:

As you can see, we are now using the wp_list_comments() function as the method by which our individual comments are displayed. This function wraps each comment with a set of <li> elements, but this may be changed via customized parameters. We are also using the next/previous_comments_link() functions to accommodate the new built-in paged comments feature.

Source: Digging into WordPress

Backwards-Compatible Comment Templates 

The easiest way to accommodate for both old (pre-2.7) and new (2.7+) WordPress comment loops is to create two different versions of the comments template and then use some conditional logic to process the correct file. Place the 2.7-compatible code from the previous section into your default comments.php file, and then place your existing (pre-2.7) comments code into a file called legacy-comments.php. Once you have both of these files setup and included among your theme files, place the following function in your theme’s functions.php file:

This code will then check for the presence of the new wp_list_comments() function. If it exists, then the version of WordPress is at least 2.7, and the default comments.php file will be used. If the new function doesn’t exist, we have a dinosaur on our hands and so the legacy comments file will be used instead.

Disable WordPress Post Revisions 

One of the new features rolled out in WordPress 2.6 involved post revisions. Revisions are a way for users to keep a working collection of each different version of a post and then revert back to it in the future if necessary. Some people think this is the greatest thing since lightsabers, others (such as myself) find it to be a royal pain in the database. It convolutes the Admin area, gobbles up disk space, and usually doesn’t work as intended. Fortunately, we can disable this amazing new “feature” (which should NOT have been included in the core) by adding the following line to the wp-config.php file:

Just place that line above the “Happy blogging” comment and say goodbye to needless revisioning bloat.

Source: Digging into WordPress

Limit WordPress Post Revisions 

If you like the idea of WordPress-2.6’s new post-revisioning feature, but don’t want thousands of extra records bloating up your database, here is an easy way to limit the total number of revisions that WordPress is allowed to keep. This code will instruct WordPress to keep only the most recent “x” number of revisions:

Place that line above the “Happy blogging” comment in the wp-config.php file and enjoy conserved disk space and less Admin clutter. Change the number 3 to any number you wish. Works a treat.

Source: Digging into WordPress

Remove WordPress Post Revisions from the Database 

In line with the previous two sections, here we will remove all existing post revisions from the WordPress database. This is useful if you have disabled the post-revisioning feature or perhaps even reduced the total number of allowed revisions. The easiest way to do this is to run the following SQL command via your favorite database interface (such as my personal favorite, phpMyAdmin):

Note that if you have changed the default WordPress database table prefix to something other than wp_, you will want to edit the command to reflect the correct prefix information. This information is available in your site’s wp-config.php file. Also note that you should backup your database before casting any SQL spells on it.

TinyURL for this post: https://tinyurl.com/y3vlpp3o

Sorry, The Comment Form Is Temporarily Closed At This Time
You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More