Embedding a Video in a Template File

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

 

wp_is_mobile

November 4, 2014 (5 years ago)
WordPress, Questions

Curious as to what you have/would use this function for?

Since it only detects browser agent and disregards size, what would you show/hide only for mobile viewers?

http://codex.wordpress.org/Function_Reference/wp_is_mobile

Replace “Howdy” in Admin Bar

October 20, 2014 (5 years ago)
WordPress, Functions

Use this function to replace “Howdy, $username” with “Welcome, $username”:

 Thanks to Thoriq Firdaus! Replayed from: http://www.hongkiat.com/blog/wordpress-howdy-customized/, where you’ll also find a clever function to customize the message for special occasions.

Don’t Delete Custom Fields on Quick Edit Save

October 20, 2014 (5 years ago)
WordPress, Plugins

When saving custom fields from a custom metabox, if the value is empty, usually the custom field is deleted. This is good, as it keeps from having lots of empty entries in the database.

However, it means that when you update from the “Quick Edit” menu, since your custom fields are not in the form, they will disappear. Not so good.

Here’s the fix.  Add this to your save function for the metabox:

 So, your save function should look something like this:

 

Database Maintenance

October 17, 2014 (5 years ago)
WordPress, Database

WordPress automatically deletes items you have trashed (posts, pages, etc) after 30 days. You can set this to fewer days to keep them from building up.

Put this in your wp-config.php file:

 

Limiting Revisions

October 17, 2014 (5 years ago)
WordPress, Database

To keep your database from bloating with endless revisions, you can limit the number that’s stored for each post.

Put this in your config.php file. (The second parameter is the number of revisions to keep.)

 

Load Child and Parent Style CSS

October 15, 2014 (5 years ago)
WordPress, CSS

If you are creating a child theme, you have two choices that load faster than using @import in your child style.css file.

1. You can add the parent style link to the child header.php, just above your normal css link.

 

2. You can add this to your functions.php file.

 

 

« Previous - Next »

Skip to toolbar