Archived topic
Kindly share code
7 replies · Started by Jim on September 16, 2019
Hi. would you kindly share the following PHP function you use for:
1. Changing image sizes in archives only https://docs.generatepress.com/article/adjusting-the-featured-images/
2. Changing the read more text in the free theme version.
Thanks in advance.
Hi there,
1. That depends on if your posts page is the front page or not. You can see all the conditional tags here though:
https://codex.wordpress.org/Conditional_Tags
2. GP Premium is needed for that unfortunately. Otherwise you will need to overwrite this copy and paste this file and overwrite this line:
https://github.com/tomusborne/generatepress/blob/7fdcddf18209a84aaa75304ab23f768241e08ed4/inc/structure/post-meta.php#L299
1. I should have mentioned this is for the free version too. Which of these two codes is correct?
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' );
function tu_variable_image_sizes( $atts ) {
// Set up our conditional
if ( is_home() || is_archive() || is_search() || is_tax() ) {
$atts[ 'width' ] = 740;
$atts[ 'height' ] = 402;
$atts[ 'crop' ] = true;
}
// Return our options
return $atts;
}
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' );
function tu_variable_image_sizes( $atts ) {
// Set up our conditional
if ( is_home() || is_archive() || is_search() || is_tax() ) {
return 'blog-thumb'; // Already registered thumbnail
}
// Return our options
return $atts;
}
That looks ok.
What if you go ! is_single() for "is not single post"?
This is the only code that worked.
add_filter( 'generate_page_header_default_size', function( $size ) {
if ( is_home() || is_archive() || is_search() || is_tax() ) {
return 'blog-thumb';
}
} );
I want to exclude both single posts and pages, but show the new thumbnail size sitewide for homepage, categories, tags, search page, etc. How will your code look like? The full size image for single posts and pages scales nicely on mobile devices.
Your code should work then :)
Okay, thanks. I can now deploy the test site.
No problem :)