3

I am trying to get my child theme to work and to overide one line of code in the main theme functions.php but I can not getting to work since I am totally green in php.

In my main theme functions.php I have:

add_image_size('portfolio-three', 300, 214, true);

When I change it directly, change the image size it works like a charm and resizes images in my portfolio page. But I want to include it in child theme. The code of the functions.php in child theme is like this:

        <?php
    function mytheme_child_scripts() {
        if ( ! is_admin() && ! in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
            $theme_info = wp_get_theme();
            wp_enqueue_style( 'mytheme-child-stylesheet', get_template_directory_uri() . '/style.css', array(), $theme_info->get( 'Version' ) );
        }
    }
add_action('wp_enqueue_scripts', 'mytheme_child_scripts');
add_image_size('portfolio-three', 388, 214, true);
?>

And it does not work, nothing happens, no error and also no image resize. I do not know what to do here. Could anyone please help me with implementing it properly ?

Best regards! Jacek

  • Are you using add_image_size into theme_setup action hook? – cybmeta Feb 16 '15 at 8:37
  • I do not know what 'hook' you are mentioning and what it is but if I understand you correctly, you mean my additional code is in the wrong place in the document ? I do not know how to properly implement this resize change. – doktor-x Feb 16 '15 at 8:43
  • I mean after_theme_setup, sorry. – cybmeta Feb 16 '15 at 8:46
  • Well I have no idea, I am unfortunately not familiar with the concept of php functions and child themes - it is my first time. My custom css in child theme is working fine, but I need to add also the "add_image_size" to the child theme functions but I do not know how to insert it properly. I do not know if it should be at the beggining of the functions.php or at the end so that is why I am seeking help because I know that community here can fix that in seconds. – doktor-x Feb 16 '15 at 8:51
6

I would like to thank very much cybmeta for pointing me tho the other thread where I could find a solution to my problem. All works perfectly now and I am glad I received help so fast.

I have modified my child functions.php like below:

<?php
function mytheme_scripts() {
    if ( ! is_admin() && ! in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
        $theme_info = wp_get_theme();
        wp_enqueue_style( 'mytheme-child-stylesheet', get_template_directory_uri() . '/style.css', array(), $theme_info->get( 'Version' ) );
    }
}
add_action('wp_enqueue_scripts', 'mytheme_child_scripts');
function child_theme_setup() {
    add_image_size('portfolio-three', 359, 214, true);
}
add_action( 'after_setup_theme', 'child_theme_setup', 11 );

It now works like a charm. Thank you mr cybmeta and best regards to you and all the community.

Not the answer you're looking for? Browse other questions tagged or ask your own question.