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

0 1,236,174
:3of8
1
2
3
4
5
6
7
8
Most Useful .htaccess Tricks for WordPress | A&H Business Technology
Related posts

Normally, you would access the wp_options table using a database interface such as phpMyAdmin. This certainly works, but there is a much easier way to work with the options table, especially if you are already logged into WordPress. Once logged in to the Admin area, navigate to the following URL:

This will open a “secret” Admin page that provides editable options fields for every record in the wp_options table. Bookmark this page, and save yourself a trip to phpMyAdmin!

Source: Digging into WordPress

Alternate Comment Styles 

Alternating comments for old versions of WordPress (pre-2.7)
This is one of the oldest tricks in the book, but it is still a favorite. Alternating comment styles is a great way to enhance usability and add some stylistic flair to your comments display. The trick is to add an alternating set of classes — odd or even — to the containing element of each comment. While there are many ways to do this, here is one of the easiest. Open your comments.php and modify the comments loop as follows:

With that code in place, your comments will now have alternating CSS classes with which to apply custom styles to your oddly and evenly numbered comments:

Alternating comments for old versions of WordPress (pre-2.7)
In WordPress 2.7 and better, comments automagically include odd and even classes for oddly and evenly numbered comments, respectively. This makes it a snap to throw down your own custom CSS styles for each of these classes.

Automatically Remove Code Mistakes in Posts 

Here is a handy trick that will automatically remove basic mistakes in XHTML markup, such as empty paragraphs, inline font styles, and more. Place this function in your functions.php file:

Once in place, use the following function call to display your “cleaned” content in the loop:

Note that the clean_bad_content() accepts a boolean argument (true or false) specifying whether or not to print the function output.

Automatically Disable Comments and Trackbacks in Old Posts 

Here is yet another method for auto-disabling comments and trackbacks on old posts. This function automatically closes comments and trackbacks after the specified number of days. Add the following to your functions.php file:

Once in place, you may change the number of days allowed for comments and trackbacks to stay open by editing the two instances of the $age variable to whatever you wish. No other editing or code is required for this function to operate effectively. The function is executed automatically upon various posting actions. Note that this function is included in newer versions of WordPress (2.7 or better), and is therefore only required for older versions.

Source: WP Engineer
Plugin: Autoclose

Access Post Data Outside the Loop 

The easiest way to access and display post data outside of the loop is to use the built-in WordPress core function get_post(); however, for more control over the process, check out this nifty little function from WP Recipes:

Place this function in your functions.php and then add this code to the desired location outside of the loop:

For the argument of the function, specify the post ID for which you would like to display data. The function will return an array containing all of the available fields for the specified post (post_titledatecontentauthor_idpost_id, etc).

Display Posts for a Specified Time Period 

Here is an easy way to create posts that will only be displayed for the duration of a specified time period. Replace your current loop with the following:

And then add a custom field named expiration to any post that needs an expiration date. For the value of the expiration key, specify the date/time in the following format: mm/dd/yyyy 00:00:00. Each post that contains such a custom field will expire after the specified date and time and will no longer appear in the loop.

Unique Single Post Templates for Different Categories 

Here is an easy way to display custom post styles depending on the post’s category. With the following code, each single-view post will be displayed according to a template that is specific to the post’s category:

This code should be placed in your theme’s single.php file. As written, this code will display posts from the first category with the single template, single-01.php; also, posts from the second category will be displayed with a single template named single-02.php; finally, all other posts will be displayed via the default single template, single-default.php. Of course, you will want to customize the category IDs according to your own needs, and also you will want to create the customized single files as they are called. That’s all there is to it.

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

Sorry, The Comment Form Is Temporarily Closed At This Time
:3of8
1
2
3
4
5
6
7
8
3
Next
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

Language:English