HOWTO: Simple Bootstrap 4 WordPress Gallery

If you are looking for a simple way to have your WordPress inserted galleries use the Bootstrap 4 layout – look no further. Just drop this code into your theme’s functions.php file and any WordPress gallery you insert when selecting media ([ gallery ids=”” ]) will then use the Bootstrap layout.

Code Needed for the WordPress Gallery

/**
 * Bootstrap 4 gallery
 */
add_filter( 'post_gallery', 'lucidity_bootstrap_gallery', 10, 2);
function lucidity_bootstrap_gallery( $output = '', $atts, $instance ) {
    if (strlen($atts['columns']) < 1) $columns = 3;
    else $columns = $atts['columns'];
    $images = explode(',', $atts['ids']);
    
    // Set the # of columns you would like
    if ( $columns < 1 || $columns > 12 ) $columns == 3;
    
    $col_class = 'col-lg-' . 12/$columns;
    
    $output = '<div class="row text-center text-lg-left gallery">';
    $i = 0;
    
    foreach ( $images as $key => $value ) {
       
        $image_attributes = wp_get_attachment_image_src( $value, 'thumbnail');
        $output .= '
            <div class="'.$col_class.'">
              <a data-gallery="gallery" href="'.esc_url($image_attributes[0]).'" class="d-block mb-4 h-100">
                    <img src="'.esc_url($image_attributes[0]).'" alt="" class="img-fluid img-thumbnail">
                </a>
            </div>';
        $i++;
    }
    
    $output .= '</div>';
    
    return $output;
} 

A few things to note:

  1. This example uses the image size “thumbnail”. If you want to use something different – you can change that here on this line: $image_attributes = wp_get_attachment_image_src( $value, ‘thumbnail’);
  2. This example uses 3 columns. Depending on the size of your images – you may also what to change that. You can make the change by changing the two references to “3” in the code above ($columns == 3, $columns = 3)

You can see the gallery in action here: http://www.jappler.com/2014/07/25/recent-visit-911-memorial/

WordPress 4.9.5 Security and Maintenance Release Available

WordPress 4.9.5 is a security release for all previous versions since WordPress 3.7

Things to note

It is highly recommended you update your sites immediately in order to apply important security and the additional 25 bug fixes. You can read more by looking at the release notes: https://codex.wordpress.org/Version_4.9.5

If you have not done so already – download the update or simply use your existing installation of WordPress to update your site. Either way – this is an excellent time to make a backup copy of your site(s) before upgrading.

WordPress 4.9.4 Maintenance Release Available

WordPress 4.9.4 contains a fix for a severe bug which stops automated updates.

Things to note

WordPress 4.9.4 should be appplied to your site(s) in order to address a bug introduced in WordPress 4.9.3 which makes any site that uses automated updates stop updating. You will need to manually update WordPress in order for the automated updates to continue. You can read more by looking at the release notes: https://codex.wordpress.org/Version_4.9.4

If you have not done so already – download the update or simply use your existing installation of WordPress to update your site. Either way – this is an excellent time to make a backup copy of your site(s) before upgrading.

WordPress 4.8.2 Security/Maintenance Release Available

WordPress 4.8.2 is a security and maintenance release that should be applied immediately.

Things to note

WordPress versions 4.8.1 and earlier are affected by nine security vulnerabilities that are addressed in the 4.8.2 version update. Along with the security updates – there are multiple maintenance fixes to this new version as well. You can read more by looking at the release notes: https://codex.wordpress.org/Version_4.8.2

If you have not done so already – download the update or simply use your existing installation of WordPress to update your site. Either way – this is an excellent time to make a backup copy of your site(s) before upgrading.

WordPress 4.7.5 Security Release Available

WordPress 4.7.5 is a security release and should be applied immediately.

Things to note

All earlier versions of WordPress are affected by multiple security issues and we suggest you update your current site to this version. This version also includes 3 maintenance fixes to the 4.7 release series. You can read more by looking at the release notes: https://codex.wordpress.org/Version_4.7.5

If you have not done so already – download the update or simply use your existing installation of WordPress to update your site. Either way – this is an excellent time to make a backup copy of your site(s) before upgrading.

WordPress 4.7 Update Now Available

WordPress 4.7 makes WordPress easier to customize the way you want it.

Things to note

  • New Twenty Seventeen theme
  • Customizer allows you to set up your theme easier in the initial set up as well as allows you to easily preview changes without actually making the changes to the site until you are happy with what you see.
  • Themes can now provide starter contact to get you up and ready faster.
  • Header background video now are available
  • Creating menus/adding custom CSS is now easier.
  • PDF thumbnails allow you to quickly view your documents in the media library
  • Creating menus/adding custom CSS is now easier.
  • Users can now choose their own language of the dashboard
  • Long awaited – we now have the WP REST API built into WordPress 4.7
  • All sort of great functionality for developers as well including new functions, hooks, post type templates, etc

If you have not done so already – download the update or simply use your existing installation of WordPress to update your site. Either way – this is an excellent time to make a backup copy of your site(s) before upgrading.

As always, a big thanks to all the contributors for their time and attention to the new features/fixes!

HOWTO: Add TinyMCE to a Textarea in WordPress

If you are building a plugin or simply adding some custom fields for your theme and would like to use the WordPress Visual/HTML editor – you can – with one easy line of code:

<?php wp_editor( $content, $editor_id, $settings = array() ); ?>

No extra added JS or anything else is needed! It is that simple. (This was introduced with WordPress 3.3)

Used in a real world example (custom fields for a custom post type):

<?php wp_editor( $sdac_profile_general_description, 'sdac_profile_general_description' );?>

That outputs a text area with the name “sdac_profile_general_description” and the value of the custom field.

I hope this helps out next time you find yourself wanting the Visual/HTML editor in place but struggling to get all the needed JS/HTML in place.

Further Documentation: http://codex.wordpress.org/Function_Reference/wp_editor

Easily Add Page Excerpts in WordPress

Ever need to add an excerpt field for WordPress when working with pages? There is an easy, one line way to do this (no plugin needed). Simply add this to your theme’s functions.php file:

add_post_type_support( 'page', 'excerpt' );

Once you have that in place – you can then use the WordPress the_excerpt() function to show the excerpt within the theme.

WordPress 3.2 is Available

WordPress 3.2 has officially been released. The update contains a number of changes making WordPress faster with a refreshed backend user interface. You can read more about all the changes and updates that went into 3.2 if you are interested. You can also see all the specific changes/fixes as well.

Download the latest versions of WordPress: WordPress 3.2

Using meta_query With WordPress 3.1+

With WordPress 3.1 – we now have the ability to use “meta_query” to show posts associated with a certain custom field. I recently used this in order to create an events listing widget for a client. I needed to query posts in the “Events” category and that had a time stamp defined (which happened to be the start date of the event). The client wanted to show only current/future events (today or later) and wanted to show them in order by the closest event date to the furthest away.

Getting the general query together was a snap – but the orderby did not work unless I had the meta_key defined (this is documented but was overlooked initially).

Example

$now = time();
$args = array(
	'category_name' =&gt; 'Events',
	'meta_query' =&gt; array(
		array(
			'key' =&gt; 'sdac_event_time_stamp',
			'value' =&gt; $now,
			'compare' =&gt; '&gt;=',
			'type' =&gt; 'NUMERIC'
		)
	),
	'meta_key' =&gt; 'sdac_event_time_stamp',
	'order' =&gt; 'ASC',
	'orderby' =&gt; 'meta_value_num'
 );
$events_query = new WP_Query( $args); 

If you take a look at the query itself – the trick was to capture the time now ($now) and then use the compare within the meta_query. Overall – this sort of query makes working with custom fields a lot easier. If you have not checked it out yet – take a look.

Documentation
Function Reference/WP Query