Skip to content

Instantly share code, notes, and snippets.

@infn8
Last active April 5, 2018 11:11
Show Gist options
  • Save infn8/43f8f94437637453f6a5 to your computer and use it in GitHub Desktop.
Save infn8/43f8f94437637453f6a5 to your computer and use it in GitHub Desktop.
Wordpress Bootstrap Image Sizes

Instructions

Add the code above to your theme's functions.php file.

Alter the size of $containerLG if you have changed the BS 3 grid. you can then call the images in you themes like so:

<?php 
the_post_thumbnail( 'col-lg-3'); 
?> 

That will call an image that's maxed at a width of 1/4 of the full container width.

function add_theme_features() {
// Add Image Sizes
$containerLG = 1170; // Change this if you have updated the largest bootstrap container width.
for ($i=1; $i <= 12; $i++) {
add_image_size(
'col-lg-'.$i,
ceil($containerLG / 12 * $i),
ceil($containerLG / 12 * $i) * 10,
false
);
}
}
// Hook into the 'after_setup_theme' action
add_action( 'after_setup_theme', 'add_theme_features' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment