avatar

Andres Jaimes

WordPress Snippets

As a WordPress developer I have collected / created / curated many snippets that I’ve used in my projects. I hope you find them useful.  General HTML / WordPress tags Get your template’s directory <link href="<?php echo get_template_directory_uri(); ?>/style.css" rel="stylesheet" media="screen"> Check if this is the home page <?php if (is_home()) { ... } ?>  Remove the wp_generator tag in the Head section of your HTML I recommend you to add this line for security reasons.

Creating Shortcodes in WordPress

Shortcodes enable developers to create special kinds of content, following the idea of macros. One very famous short code is “gallery” needed to insert a gallery of images into a post. The good thing about shortcode’s is that final users are free to decide where to insert them. WordPress’s Shortcode API handles all the tricky parsing, making developers life much easier. The following is a snippet for a Shortcode – in order to make it work you have to add it to your functions.

Add a Thumbnail to Admin Post Columns in WordPress

Here is a snippet to add 64×64 images to the Admin Post Columns in WordPress. Having thumbnails may result extremely helpful, specially if you have hundreds of posts. You have to copy and paste the following code into the functions.php file of your theme. function posts_columns($defaults){ $defaults['the_post_thumbs'] = __('Thumbs'); return $defaults; } function posts_custom_columns($column_name, $id){ if($column_name === 'the_post_thumbs'){ echo the_post_thumbnail( array(64, 64) ); } } add_filter('manage_posts_columns', 'posts_columns'); add_action('manage_posts_custom_column', 'posts_custom_columns', 10, 2);  Instead of array(64, 64) you can also use default image sizes like ‘featured_thumbnail’, ‘thumbnail’, ‘medium’, ‘large’ and ‘full’.

10 WordPress plugins you should have

This time I would like to make a list of recommended WordPress plugins. They are alphabetically sorted and have many different purposes. The descriptions shown were taken right from the WordPress description. Here we go: 1. Comment Rating By Bob King Description: Allows visitors to rate comments in a Like vs. Dislike fashion with clickable images. Poorly-rated & highly-rated comments can be displayed differently. This plugin is simple and light-weight.

How to Move a WordPress Blog to a New Domain or Location

Before trying the queries in this page, I recommend you to read this full article to learn more about the process. To update WordPress options with the new blog location, use the following SQL command: UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl'; After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field.