Articles in the Cheat Sheets Category
This page has a list of all the available WordPress constants defined by WordPress. This list can be handy when you are modifying a WordPress plugin or theme and need to find a reference to a particular constant.
WordPress has a function that allows you to retrieve the content of a remote webpage so you can do something with it. There are two functions that you can use:
wp_remote_get (Retrieve the webpage content using HTTP GET)
wp_remote_post (Retrieve the webpage content using HTTP POST)
Example Code to Retrieve Remote Webpage Content using HTTP GET Method
$response = wp_remote_get( ‘http://www.example.com/some-text-file.txt’ );
if(is_wp_error($response))//check to see if any error occured
{
echo ‘An error orccured when trying to retrieve the remote webpage content!’;
print_r($response); //This will dump more data
}
else //webpage content was retrieved successfully
{
echo ‘Here is the retrieved content:’;
echo …
To show the tags associated with a WordPress post from your template file automatically simply open the “single.php” template file from your theme and add the following line of code where you want to show the tags:
<?php the_tags(‘<strong>Tags: </strong>’,’ , ‘); ?>
The above code will display a list of the tags associated with the post in question separated by comma (,).
When using the WP eStore and Thesis Theme you may run into the issue of your images displaying too big or small. There is a simple fix for this as I will explain in this cheat sheet.
The Thesis theme specifies a width for the input fields in it’s theme CSS. This makes it so images have a specific size and will cause them to be stretched or smooched.
To fix this issue all you need to do is override the CSS of the theme by adding the following CSS code in the …
This little snippet of code will make it so the copyright year on your site is always current. We all tend to forget to change this after the new year. =)
If you want to add some custom content at the end of every post (for example, the author info) then copy the following code and paste it in the “functions.php” file of your theme.
[php]
function add_post_content($content)
{
if(!is_feed() && !is_home())
{
$content .= ‘<p>This article is written by ‘.the_author();
}
return $content;
}
add_filter(‘the_content’, ‘add_post_content’);
[/php]
Now the custom content from the “add_post_content” function will be inserted below each of your posts.
To randomize posts order, you simply have to use the query_posts() function before the WordPress loop like the following:
<?php query_posts(‘orderby=rand’); ?>
<?php //WordPress loop goes here ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
WordPress has many hooks that you as a plugin developer can take advantage of while developing a plugin. This page documents the API (Application Programming Interface) hooks available to WordPress plugin developers. This article is specifically about the API of “Hooks”, also known as “Filters” and “Actions”, that WordPress uses to set your plugin in motion.
Available “add_action” Hooks
Actions are (usually) triggered when the WordPress core calls do_action(). It can be used in the following way:
add_action (‘hook_name’, ‘your_function_name’, [priority] , [accepted_args]);
admin_footer
admin_head
admin_menu
comment_closed
comment_form
comment_id_not_found
comment_post
delete_comment
delete_post
edit_comment
…
If you are trying to tweak or develop a WordPress theme then this post should help making your life a bit easier. This post has a list of all the WordPress functions that you can use from your theme’s template file.
Useful PHP Code for Header
<?php bloginfo(‘name’); ?>
Title of the site
<?php wp_title(); ?>
Title of the post or page
<?php bloginfo(‘stylesheet_url’); ?>
The style.css file’s location
<?php bloginfo(‘pingback_url’); ?>
Pingback URL for the site
<?php bloginfo(‘template_url’); ?>
Location …






