[Resolved] Kindly share code

Home Forums Support [Resolved] Kindly share code

Home Forums Support Kindly share code

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1010764
    Jim

    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.

    #1010781
    Leo
    Staff
    Customer Support

    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

    #1010829
    Jim

    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;
    }
    #1010836
    Leo
    Staff
    Customer Support

    That looks ok.

    What if you go ! is_single() for “is not single post”?

    #1010858
    Jim

    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.

    #1010877
    Leo
    Staff
    Customer Support

    Your code should work then ๐Ÿ™‚

    #1010889
    Jim

    Okay, thanks. I can now deploy the test site.

    #1010927
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.