Automatically wrap images in the_content with custom html

Posted by & filed under WordPress.

Adding this snippet to the functions.php of your WordPress theme will automatically wrap images in the_content with any custom HTML that you wish. function filter_images($content){ return preg_replace(‘/<img (.*) \/>\s*/iU’, ‘<span class=”className”><b><img \1 /></b></span>’, $content); } add_filter(‘the_content’, ‘filter_images’);

Disable dragging of metaboxes within admin

Posted by & filed under WordPress.

Adding this snippet to the functions.php of your WordPress theme will disable all dragging of metaboxes within the admin. Please note that this includes dashboard widgets as well. function disable_drag_metabox() { wp_deregister_script(‘postbox’); } add_action( ‘admin_init’, ‘disable_drag_metabox’ );

Check if post / page has a gallery

Posted by & filed under WordPress.

Adding this snippet to your WordPress theme will let you check to see if a post contains the gallery shortcode. Add this code to the single.php template of your WordPress theme inside the loop. if (get_post_gallery() ){ echo ‘has gallery’; } else { echo ‘has no gallery’; } If you want to show the gallery

Continue reading →