Web & Software Developer

Archive for “WordPress Functions”

Quick snippets of Wordpress functions to paste in the functions.php file of your theme.

Upload Images To Media Library From Your Theme in WordPress

This lets you upload images from a theme or plugin right into the WordPress Media Library. This leaves the images unattached to any post. They will simply be sitting in the Media Library ready for use. If you want to attach the image to a post, or to set it as the featured image, see […]

Equal Heights For WordPress Image Gallery Captions

This gives your WordPress image captions equal heights on a gallery page. The text captions will take the height of the tallest caption on the page. This applies to the “gallery-caption” element, not to the entire “gallery-item” element. This is useful if you added a background color for your “gallery-caption” or “wp-caption-text“. Captions with a […]

Dynamically Add a Sub-menu Item to wp_nav_menu

This function will add a sub-menu item to an existing menu item in wp_nav_menu, only if a user is logged in. Replace ‘main-menu’ on line 8 with the Theme Location of the menu that you want to modify. Use the slug of the location name. Find the Theme Location name in “Appearance -> Menus -> […]

Remove Query Strings from Static Sources in WordPress

This function will remove the “?ver” from the URLs of of your static resources on your WordPress site. For example, it will remove the “version” from the link to your .css and .js files. from This increases your page speed. However, please note that some WordPress plugins depend on the query strings and thus will […]

Custom Excerpt “Read More” Link for Custom Post Types

Add a custom “Read More” link for excerpts of your custom post type. This example replaces the “[…]” which WordPress automatically appends to excerpts. It adds instead an ellipsis followed by “Read more →”. To add “Read more” to regular post excerpts, see Custom “Read More” Link For Excerpts in WordPress. In the sample below, […]