Skip to content

Instantly share code, notes, and snippets.

@ozzyrod
Created June 20, 2018 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzyrod/7671f37f2532d488aee2d56c6677edd5 to your computer and use it in GitHub Desktop.
Save ozzyrod/7671f37f2532d488aee2d56c6677edd5 to your computer and use it in GitHub Desktop.
Cookbook change image size on Print Page
<?php // Do not include this opening line in your functions.php
/**
* Remove the standard Cookbook image
*/
remove_action( 'cookbook_recipe_print_top', 'cookbook_template_image', 5 );
/**
* Add the image size you'd like used.
* See https://developer.wordpress.org/reference/functions/add_image_size/ for
* more information.
*/
add_image_size( 'themeprefix-cookbook-print-image-size', 150, 0, true );
/**
* Display the recipe's updated print image.
*
* @param Cookbook_Recipe $recipe The current cookbook recipe object.
* @return void
*/
function themeprefix_template_image( $recipe ) {
if ( $recipe->has_image() ) {
echo '<div ' . cookbook_get_attr( $recipe, 'image' ) . '>' . $recipe->image( 'themeprefix-cookbook-print-image-size' ) . '</div>';
}
}
/**
* Add the updated image to the print page.
*/
add_action( 'cookbook_recipe_print_top', 'themeprefix_template_image', 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment