Fun new code snippets…


Aqua Resizer

Aqua Resizer is a great tool for ensuring that your sites images always get output at the correct sizes.  This little script by, Syamil MJ, is easy to use and works great for resizing, cropping, and scaling images on the fly.

Simply add the aq_resizer.php file to your site. I like adding extra files like this to a ‘lib’ directory, but you can put it in the root of a theme if you’d like.  You just need to know how to reference it in your functions.php file.

Using the require once command in your functions.php file, make sure it gets included.
require_once( dirname(__FILE__) . '/lib/aq_resizer.php');

Then, where ever you need to retrieve and resize images use the following code snippet:

//you will need to download aqua resizer and upload it to your project
//https://github.com/syamilmj/Aqua-Resizer
require_once( dirname(__FILE__) . '/lib/aq_resizer.php');

//working example
    
    $project_image = get_post_meta($portfolioItem->ID, '_portfolio_project_page_image', true);

    $original_image = $project_image; // let's assume this image has the size 100x100px
    $width = 410; // note, how this exceeds the original image size
    $height = 267; // some pixel less than the original
    $crop = true; // if this would be false, You would get a 90x90px image. For users of prior
    // Aqua Resizer users, You would have get a 100x90 image here with $crop = true
    $new_image = aq_resize($original_image, $width, $height, $crop);

    ?>
    
    <?php echo '<img class="img-responsive" src="'. $new_image. '">'; ?>

Note: In the snippet above, you can specify what ever image dimensions you’d like.

CMB2: This has become my favorite plugin.  I know a lot of people like Advance Custom Fields, but I got started with this one and have just been loving it ever since.  I will be doing an in depth on this in the near future.  Stay tuned, but here is a little teaser:

add_action( 'cmb2_admin_init', 'aa_projects_register_repeatable_group_field_metabox' );
/**
 * Hook in and add a metabox to demonstrate repeatable grouped fields
 */
function aa_projects_register_repeatable_group_field_metabox() {

    // Start with an underscore to hide fields from custom fields list
    $prefix = '_aa_projects_group_';

    /**
     * Repeatable Field Groups
     */
    $cmb_group = new_cmb2_box( array(
        'id'           => $prefix . 'metabox',
        'title'        => __( 'Repeating Field Group', 'cmb2' ),
        'object_types' => array( 'projects', ),
    ) );

    // $group_field_id is the field id string, so in this case: $prefix . 'demo'
    $group_field_id = $cmb_group->add_field( array(
        'id'          => $prefix . 'slides',
        'type'        => 'group',
        'description' => __( 'Generates reusable form entries', 'cmb2' ),
        'options'     => array(
            'group_title'   => __( 'Entry {#}', 'cmb2' ), // {#} gets replaced by row number
            'add_button'    => __( 'Add Another Entry', 'cmb2' ),
            'remove_button' => __( 'Remove Entry', 'cmb2' ),
            'sortable'      => true, // beta
            // 'closed'     => true, // true to have the groups closed by default
        ),
    ) );

    /**
     * Group fields works the same, except ids only need
     * to be unique to the group. Prefix is not needed.
     *
     * The parent field's id needs to be passed as the first argument.
     */

    $cmb_group->add_group_field( $group_field_id, array(
        'name' => __( 'Entry Image', 'cmb2' ),
        'id'   => 'images',
        'type' => 'file',
    ) );

}

and
<?php $hpSlider = get_post_meta( $slider_id, 'aa_slides_group', true );
    foreach ( (array) $hpSlider as $slide ) {
    $img = $title = '';
    if ( isset( $slide['message'] ) )
    $title = esc_html( $slide['message'] );
                                    
    if ( isset( $slide['image_id'] ) ) {
    $img = wp_get_attachment_image( $slide['image_id'], 'share-pick', null, array(
    'class' => 'thumb img-responsive',
    ) );
} ?>

Dashicons: https://developer.wordpress.org/resource/dashicons/#forms – for when you are creating custom post types and need an icon to display next to the name in the admin panel.
Isotope.js: I recently wrote a article on this for the Layout. https://getflywheel.com/layout/how-to-add-filters-to-your-wordpress-portfolio/
jQuery Flip: coming soon