Change Date Format on Import to MySQL from CSV File

September 2, 2015 (3 years ago)
Database

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:

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 (3 years ago)
WordPress, Functions

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

Thanks, Micah Wood! https://gist.github.com/wpscholar/1249995

Debugging Scripts in the Console

June 29, 2015 (3 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).

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:

 

Remove Emoji Support from WordPress 4.2

May 19, 2015 (4 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:

 Thank you, Paulund!

http://www.paulund.co.uk/disable-emojicons-introduced-in-wordpress-4-2

The Current Template Name

March 3, 2015 (4 years ago)
WordPress

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

 

Include page content in another page

March 3, 2015 (4 years ago)
WordPress

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

 

Embedding a Video in a Template File

January 11, 2015 (4 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:

 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 (4 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:

 

Manage Dashboard Columns

December 18, 2014 (4 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:

 

Allow HTML in Excerpts

December 9, 2014 (4 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:

 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.

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

 

« Previous - Next »

Skip to toolbar