Change Date Format on Import to MySQL from CSV File

September 2, 2015 (5 years ago)

You have a .csv file with a date column that is formatted like this:  12/1/2015 (‘m/d/Y’).

You need to import it into a MySQL database DATE field named “my_dates”.

A straight import will result in all your dates showing up as ‘0000-00-00’, because MySQL uses the format ‘Y-m-d’, and won’t translate it natively.

Here’s the solution:

Create a VARCHAR field named “my_text_dates” in the database, and import the dates there.

Then, run this query:

UPDATE my_table SET my_dates = STR_TO_DATE(my_text_dates, '%m/%d/%Y')

Then, just delete the “my_text_dates” field, and you’re all set!

NOTE: the ‘%m/%d/%Y’ portion of the update statement needs to match exactly the format of your text date field.

Append Item to Nav Menu

July 8, 2015 (5 years ago)
WordPress, Functions

Programmatically add an item to any menu that is called with wp_nav_menu.

add_filter('wp_nav_menu_items', 'add_admin_link', 10, 2);

function add_admin_link($items, $args){

    if( $args->theme_location == 'footer_menu' ){

        $items = $items . '<li><a title="Admin" href="'. esc_url( admin_url() ) .'">' . __( 'Admin' ) . '</a></li>';


    return $items;


Thanks, Micah Wood!

Debugging Scripts in the Console

June 29, 2015 (5 years ago)
PHP, Functions

The easiest way to see what data is being used inside a script. Add this script to your page (or in functions.php for sitewide use).

function debug_to_console( $data ) {

    if ( is_array( $data ) )
        $output = "<script>console.log( 'Debug Objects: " . implode( ',', $data) . "' );</script>";
        $output = "<script>console.log( 'Debug Objects: " . $data . "' );</script>";

    echo $output;

Then call it inside your function like this:


Then just look at your console log to see the output.

Hint: if you are tracking one variable through a script and want to see how it changes, try something like this:

debug_to_console('step 1 -' . $mydata);


Remove Emoji Support from WordPress 4.2

May 19, 2015 (5 years ago)
WordPress, JS, Functions

4.2 added the ability to use Emojicons in WP posts. If you don’t use them, you can remove the (unnecessary) scripts this adds to the header on all your site pages. Here’s the code for your functions.php file:

function pw_remove_emojicons() 
    // Remove from comment feed and RSS
    remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
    remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );

    // Remove from emails
    remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );

    // Remove from head tag
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );

    // Remove from print related styling
    remove_action( 'wp_print_styles', 'print_emoji_styles' );

    // Remove from admin area
    remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    remove_action( 'admin_print_styles', 'print_emoji_styles' );
add_action( 'init', 'pw_remove_emojicons' );

 Thank you, Paulund!

The Current Template Name

March 3, 2015 (6 years ago)

This will output the name of the template being called on any particular page or post or archive.

   global $template; 
   $name = $template_name = substr( $template, ( strripos( $template, '/') ) ); 
   echo $name; 


Include page content in another page

March 3, 2015 (6 years ago)

Here’s a quick and easy way to include content from one page into another:

$include = get_pages('include=120');
$content = apply_filters('the_content',$include[0]->post_content);
echo $content;


Embedding a Video in a Template File

January 11, 2015 (6 years ago)
WordPress, PHP

Adding shortcodes to template files is a bit tricky. Although [ embed]myvideourl[ /embed] looks like a regular WP shortcode, it’s not handled the same way.

It works just as expected in a content block, but not so in a template file. Here’s the code to embed into the template:

global $wp_embed;

echo $wp_embed->run_shortcode('[ embed]myvideourl[ /embed]');

 NOTE: To use this code, you will need to remove the spaces inside the brackets before ’embed’ and ‘/embed’.

Allow Multiple User Emails

December 23, 2014 (6 years ago)
WordPress, Functions

Ever need to allow your users to have non-unique email addresses? (i.e. two user accounts with the same email address)

Here’s the function:

add_filter('pre_user_email', 'skip_email_exist');
function skip_email_exist($user_email){
    return $user_email;


Manage Dashboard Columns

December 18, 2014 (6 years ago)
WordPress, Functions

In the latest versions of WordPress, the number of columns showing in the dashboard are automatically generated based on your screen size. That works for many situations, but you may want to control the number of columns.

For example, if  you only have 1 or 2 items showing on your dashboard, it looks awkward on a large screen. So, here is a function that allows you to control the default and max number of columns:

function lt_dashboard_columns() {
            'max'     => 2,
            'default' => 1
add_action( 'admin_head-index.php', 'lt_dashboard_columns' );


Allow HTML in Excerpts

December 9, 2014 (6 years ago)
WordPress, PHP, Functions

By default, WordPress strips all HTML tags from excerpts. To allow them, simply replace the filter that creates the excerpt from your content.

First, copy the default excerpt filter from wp-includes/formatting.php:

function wp_trim_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
        $text = get_the_content('');
        $text = apply_filters('the_content', $text);
        $text = str_replace('\]\]\>', ']]&gt;', $text);
        $text = strip_tags($text);
        $excerpt_length = 55;
        $words = explode(' ', $text, $excerpt_length + 1);
        if (count($words)> $excerpt_length) {
            array_push($words, '[...]');
            $text = implode(' ', $words);
    return $text;

 By changing the strip_tags parameters, you can allow whatever tags you want:

Also be sure to change the name of the function. Copy this to your functions.php file.

function lt_html_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
        $text = get_the_content('');
        $text = apply_filters('the_content', $text);
        $text = str_replace('\]\]\>', ']]&gt;', $text);
        /*just add all the tags you want to appear in the excerpt --
        be sure there are no white spaces in the string of allowed tags */
        $text = strip_tags($text,'<p><br><b><a><em><strong>');
        /* you can also change the length of the excerpt here, if you want */
        $excerpt_length = 55; 
        $words = explode(' ', $text, $excerpt_length + 1);
        if (count($words)> $excerpt_length) {
            array_push($words, '[...]');
            $text = implode(' ', $words);
    return $text;

 Then, replace the default filter with your new one in functions.php:

/* remove the default filter */
remove_filter('get_the_excerpt', 'wp_trim_excerpt');

/* now, add your own filter */
add_filter('get_the_excerpt', 'lt_html_excerpt');


« Previous - Next »

Skip to toolbar