• Hi Support,

    I have been googling anywhere and still can’t find a solution.
    I would like to use a child theme for my WordPress and still not working.
    It’s not about css file but about PHP code. I have copied the file and folder exactly same to child theme and edit it but it doesn’t work.
    WP still uses setting from the original theme.
    The theme I use is estore from elegantthemes and unfortunately their support is very slow and not really helpful.
    There is a file that contains code to resize image to some sizes.
    The file is located at epanel/post_thumbnails_estore.php.
    I copied it to child theme and edited the size (1st line) from 193×130 to 193×200 as shown below.

    $et_theme_image_sizes = array(
    		'193x200'	=> 'et-entry-thumb',
    		'1400x501' 	=> 'et-featured-thumb',
    		'109x109' 	=> 'et-featured-small-thumb',
    		'162x112' 	=> 'et-scroller-thumb',
    		'298x130' 	=> 'et-single-product-thumb',
    		'298x226' 	=> 'et-single-product-thumb2',
    		'44x44' 	=> 'et-related-item-thumb',
    	);

    What else I missed? pls advise.
    Thanks,
    Agus

    Complete code of file post_thumbnails_estore.php:

    <?php
    	add_theme_support( 'post-thumbnails' );
    
    	global $et_theme_image_sizes;
    
    	$et_theme_image_sizes = array(
    		'193x200' 	=> 'et-entry-thumb',
    		'1400x501' 	=> 'et-featured-thumb',
    		'109x109' 	=> 'et-featured-small-thumb',
    		'162x112' 	=> 'et-scroller-thumb',
    		'298x130' 	=> 'et-single-product-thumb',
    		'298x226' 	=> 'et-single-product-thumb2',
    		'44x44' 	=> 'et-related-item-thumb',
    	);
    
    	$et_page_templates_image_sizes = array(
    		'184x184' 	=> 'et-blog-page-thumb',
    		'207x136' 	=> 'et-gallery-page-thumb',
    		'260x170' 	=> 'et-portfolio-medium-page-thumb',
    		'260x315' 	=> 'et-portfolio-medium-portrait-page-thumb',
    		'140x94' 	=> 'et-portfolio-small-page-thumb',
    		'140x170' 	=> 'et-portfolio-small-portrait-page-thumb',
    		'430x283' 	=> 'et-portfolio-large-page-thumb',
    		'430x860' 	=> 'et-portfolio-large-portrait-page-thumb',
    	);
    
    	$et_theme_image_sizes = array_merge( $et_theme_image_sizes, $et_page_templates_image_sizes );
    
    	$et_theme_image_sizes = apply_filters( 'et_theme_image_sizes', $et_theme_image_sizes );
    	$crop = apply_filters( 'et_post_thumbnails_crop', true );
    
    	if ( is_array( $et_theme_image_sizes ) ){
    		foreach ( $et_theme_image_sizes as $image_size_dimensions => $image_size_name ){
    			$dimensions = explode( 'x', $image_size_dimensions );
    			add_image_size( $image_size_name, $dimensions[0], $dimensions[1], $crop );
    		}
    	}
    ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Consider switching to a theme distributed on www.remarpro.com, as we do not have access to commercial themes and therefore are unlikely to be able to resolve this.

    Thread Starter agusbagus

    (@agusbagus)

    Hi Andrew Thanks, I understand about your condition and limitation to commercial themes. But what I need is basically to learn how child theme works.
    I read from everywhere about child theme is just need to copy the PHP file and folder exactly the same hierarchy to child theme and edit it from there.
    But it doesn’t work in my case.

    Thanks,
    Agus

    No, that’s not how the functions.php file works in a child theme – see the link I posted above.

    Thread Starter agusbagus

    (@agusbagus)

    Hi Yogi,

    I checked the code (posted above), it doesn’t contain function, does it?
    Sorry my PHP skill is not really good.
    Thanks for your advice.

    Agus

    Thread Starter agusbagus

    (@agusbagus)

    I have function.php in child theme and contains one function there that works. But I copied above code to function.php it doesn’t work.

    [bump moderated]

    You copied the parent theme’s functions.php file into your child theme folder and are just editing it, yeah?

    The problem is, a child theme’s functions.php file does not override that of the parent theme; they both get loaded. I am familiar with Elegant Themes (and their poor customer service), so I will take a look…

    Okay, first I would recommend starting with an empty functions.php file in your child theme — or one that only contains functions you wrote.

    Next, add this somewhere inside your PHP tags:

    function overwrite_et_image_size_06082013() {
        global $_wp_additional_image_sizes;
        $name = 'et-entry-thumb';
        $_wp_additional_image_sizes[$name] = array(
            'width'  => 193,
            'height' => 200,
            'crop'   => true
        );
    }
    add_action( 'after_theme_setup', 'overwrite_et_image_size_06082013', 99 );

    That should overwrite the image size.

    Thread Starter agusbagus

    (@agusbagus)

    Hi Shoun,
    Thanks for helping.
    I have tried exactly as instructed but still not working. Still can’t find an image with size 193*200.
    I found at function.php parent theme this line code:

    require_once($template_dir . '/epanel/post_thumbnails_estore.php');

    Is this something I should add to function child theme?
    I tried but it didn’t work or I added it wrong way?

    Full code of function.php parent theme can be found here:
    https://pastebin.com/vBPbBPYz

    Sorry, I messed up the action hook…it’s supposed to be after_setup_theme, not after_theme_setup.

    So change that last line to:

    add_action( 'after_setup_theme', 'overwrite_et_image_size_06082013' );

    You’ll notice I removed the ’99’ from the end there. I read up on the order of things, and apparently the child theme functions.php file loads first, then the parent theme’s functions.php, then the after_setup_theme hook fires. So no need to give this function a different priority, because it will run after the parent theme is loaded — which is what we want.

    Also, if you already have your images uploaded you’ll want to install and run the Regenerate Thumbnails plugin!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to use Child Theme for PHP code?’ is closed to new replies.