Created
June 20, 2018 17:41
-
-
Save ozzyrod/7671f37f2532d488aee2d56c6677edd5 to your computer and use it in GitHub Desktop.
Cookbook change image size on Print Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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