List all Posts

August 4, 2016 (8 years ago)
WordPress

Outputs a single list of all your posts.

Thanks, Mickey! (Edited a bit for simplicity)

Create Admin User via FTP

July 9, 2016 (8 years ago)
Functions

When you are locked out of your WordPress site and have no access to PHPMyAdmin, add this to your functions.php file to create a new admin user account.

Remove it from the functions file after you’re successfully logged in. (The user will remain.)

Thanks for the snippet, WPBeginner!

Adding Content to the Admin Edit Screen

October 30, 2015 (8 years ago)
Functions, WordPress

When creating custom post types, you often need custom fields for them. In the past, your options were “normal” or “side” with priorities. Depending on what else is displayed on your edit screen, these boxes could vary in where they appeared.

And sometimes you just need to add a comment or note to the edit pages.

Good News! We now have new hooks to place them precisely:

Here’s an article that explains the usage: https://make.wordpress.org/core/2012/12/01/more-hooks-on-the-edit-screen/

 

Change Date Format on Import to MySQL from CSV File

September 2, 2015 (9 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 (9 years ago)
Functions, WordPress

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 (9 years ago)
Functions, PHP

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

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 (9 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 (9 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 (9 years ago)
PHP, WordPress

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’.

« Previous - Next »