Clean wp_head() output

I’ve never liked the wp_head() output – WordPress’s default output is great for blogs and accessibility but if you’re a developer whose source-code is basically your resume, you don’t want irrelevant and un-indented code leaving skid marks behind the scenes.

Throwing this in functions.php will remove most of it.

Increase WordPress Memory Limit

Nothings worse then getting an email about someone being unable to upload a 6mb .PDF because it “exceeds the upload file size limit

Here’s the fix – but important note: raising post_max_size increases the possibility of DoS attacks on your server:

In functions.php add:

If that doesn’t work, it could be a apache restriction, in .htaccess add:

If you’re still unable to it could be a php restriction, in php.ini add:
Obviously change the 32mb/32000kb as needed.


The above worked for me 99% of the time, but I had once instance where I need to add the following into functions.php as well:

Responsive Height, Maintain Ratio

Say you have an element #banner with a background-image. On a responsive design that’s width:100%; you’ll notice your image will be auto croped by the viewport change. The solution is simple: background-size: cover; but a pain that follows is the height of the element will not scale down or up with the width change, leaving this weird empty vertical gap or a very cropped image.

Here’s a fix to figure out and change the height end_h based on the current window width, keeping background-image ratio making it responsive/scalable:

This resize happens when your script is loaded, as well as on any browser resize event.

wp_get_attachment_thumb_url() Alternative

If you have any experience with wpgetattachmentthumburl() you’ll know it’s really slow.. It’s a maze trying to figure out why, it just seems to require querying a lot of meta data.

So, to simplify WP’s queries I wrote this function to grab a thumbnail from the image’s full URL:

Then just get my thumbnail with the url

It’s not fool proof – it works for me because I know all my images are jpeg, and I know the URL of the full image, so this takes away all those extra queries (useful when my media plugin is pre-finding thumbnail URL’s of hundreds of images).

Loading GravityForms Outside of WordPress

I had a WordPress installation in /blog/, but I needed a WordPress’s GravityForm to render /contact.php an external non-Wordpress php page. I could of coded a form myself, but there are so many advantages to using GravityForms.

in contact.php in a perfect world, the following would work:

but it doesn’t — upon submission the page reloads with entered values in-tacked but no sucessful submission message or errors.

Looking in the first file in GravityForm plugin gravityforms.php, there’s a ton of actions hooked into the wp action. So by simply firing wp, the GravityForm now works, outside of a WordPress installation.

I’m neglecting wp_head() and wp_footer() which means style sheets, ajax submission and conditional logic won’t work. I also think loading wordpress this way neglects to run init, which several functions are hooks into, but I got what I needed out of simply:

Show WordPress Query Load Times

Here’s a good way to find out how many and what queries are being executed and how long it takes. Your code may be inefficient and here’s a good way to tell.

When troubleshooting

I’ve used admin_footer hook so this will show in the admin, you can use wp_footer or other late hooks to show on main site. Note $wpdb->queries will reveal table names to the source code so this shouldn’t be on public sites or proper user conditional tags should be added.

Change the Color of First Few Words PHP

If you have a header or similar and would like the first few words highlighted, here’s a nice little script. In below the class red is defined in my css, and $color would be the number of words I want coloured.

Usage would be similar to:

Domains Added on Plesk Not Receiving Emails

Servers running plesk with domains using an external DNS Zone file and external MX record may experience an email issue as qmail thinks it is sending emails to itself because of the plesk records and will try to bypasses the external DNS Zone.

To fix this, we have to tell qmail that these domains email solutions are not handled on the server.

To do this, remove the line with the problematic domain(s) from both files below: