Articles in the WordPress Hacks 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 (,).
You can use WordPress’s wp_mail() function to send emails from your WordPress site. However, the default content type is ‘text/plain’ which does not allow using HTML. If you want to send HTML emails then you will need to set the content type of the email to “text/html” by using the ‘wp_mail_content_type’ filter.This is how you can do that:
before you send your wp_mail call add a filter to wp_mail_content_type
add_filter(‘wp_mail_content_type’,'set_content_type’);
Then in your set_content_type function have it return the appropriate content type, in this case ‘text/html’
function set_content_type($content_type){
return ‘text/html’;
}
A More Compressed Way to Set …
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(); ?>
By default the WordPress’s admin login looks like the following:
If you want to change the logo to customize it then add the following piece of code to the “functions.php” file of your WordPress theme:
add_action(‘login_head’, ‘wp_custom_login_logo’);
function wp_custom_login_logo()
{
echo ‘<style type=”text/css”>’;
echo ‘h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/my-logo.gif) !important; }’;
echo ‘</style>’;
}
Make sure to upload your custom logo (my-logo.gif) to the “images” directory of your wordpress theme.






