• Following on from some difficulties I was having a few days ago (very helpfully resolved!)…

    I asked about creating a functions.php file in my Emphaino child theme and was advised:

    “Don’t worry if you don’t understand the above, simply do as I say below:

    1) Copy the function emphaino_setup() from the functions.php of the parent theme (lines 58 to 135).
    2) Paste it into the child theme’s function.php.
    3) Look for the code set_post_thumbnail_size( 150, 150, true ); in the child theme’s functions.php (pasted code) and change the values to whatever you want.
    4) Save the file and upload as applicable.”

    I tried doing that.

    1) I copied from:

    function emphaino_setup() {

    to…

    add_theme_support( ‘post-formats’, array(
    ‘aside’, ‘audio’, ‘chat’, ‘gallery’, ‘image’, ‘link’, ‘quote’, ‘status’, ‘video’
    ) );

    (I think that’s lines 58-135.)

    2) I pasted that into the functions.php file I created in my child theme directory.

    3) I changed:

    set_post_thumbnail_size( 150, 150, true );

    to…

    set_post_thumbnail_size( 300, 0, false );

    (Because I want to set a width of 300px, and retain the original aspect ratio without cropping.)

    4) I saved the file and uploaded it.

    BUT

    When I refreshed my blog, I found that all of the code I’d entered into the child theme’s functions.php now appeared as text at the top of every page, including my WordPress dashboard.

    Have I done something wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Srini G

    (@srinig)

    You probably missed the <?php .... ?> tags. Also I think you missed the last few lines of the function.

    Here’s what should go into your child theme’s functions.php.

    <?php
    function emphaino_setup() {
    
    	/**
    	 * Custom template tags for this theme.
    	 */
    	require get_template_directory() . '/inc/template-tags.php';
    
    	/**
    	 * Custom functions that act independently of the theme templates
    	 */
    	require get_template_directory() . '/inc/extras.php';
    
       /**
    	* Customizer additions
        */
    	require get_template_directory() . '/inc/customizer.php';
    
    	/**
    	 * Make theme available for translation
    	 * Translations can be filed in the /languages/ directory
    	 */
    	load_theme_textdomain( 'emphaino', get_template_directory() . '/languages' );
    
    	/**
    	 * Add default posts and comments RSS feed links to head
    	 */
    	add_theme_support( 'automatic-feed-links' );
    
    	/**
    	 * Enable support for Post Thumbnails
    	 */
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 300, 0, false ); // Post thumbnail size for excerpts and search results
    	add_image_size( 'half-width', 280, 9999 ); // Post thumbnail size for dynamic grid posts
    	add_image_size( 'full-width', 660, 9999 ); // Post thumbnail size for full post displays
    
    	$custom_header_args = array(
    		'width'                  => 940,
    		'height'                 => 140,
    		'flex-height'            => true,
    		'flex-width'             => true,
    		'default-text-color'     => emphaino_default_settings('header_textcolor'),
    		'wp-head-callback'       => 'emphaino_header_style',
    		'admin-head-callback'    => 'emphaino_admin_header_style',
    		'admin-preview-callback' => 'emphaino_admin_header_image',
    	);
    	add_theme_support( 'custom-header', $custom_header_args );
    
    	$custom_background_args = array(
    		'default-image' => emphaino_default_settings('background_image'),
    	);
    	add_theme_support( 'custom-background', $custom_background_args );
    
    	/**
    	 * This theme uses wp_nav_menu() in one location.
    	 */
    	register_nav_menus( array(
    		'primary' => __( 'Primary Menu', 'emphaino' ),
    	) );
    
    	/*
    	 * This theme supports all available post formats by default.
    	 * See http://codex.wordpress.org/Post_Formats
    	 */
    	add_theme_support( 'post-formats', array(
    		'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video'
    	) );
    
    	/**
    	 * This theme styles the visual editor with editor-style.css to match the theme style.
    	 */
    	add_editor_style();
    
    	/**
    	 * This theme uses its own gallery styles.
    	 */
    	add_filter( 'use_default_gallery_style', '__return_false' );
    }
    
    ?>

    Simply delete whatever is in your child theme’s functions.php and copy/paste the above into the file.

    Thread Starter travelndiveblog

    (@travelndiveblog)

    You’re right, I did miss the <?php …. ?> tags. Thanks for that!

    After solving that issue, I tried adding five extra image sizes to my theme by entering (for example):

    add_image_size(‘450-wide’, 450, 0, false);
    (etc. for each size)

    That didn’t work. Then I changed the code to:

    add_image_size(‘450-wide’, 450, 9999, false);

    (following the half-width and full-width sizes by defining the maximum image height as 9999 instead of 0)

    That didn’t work either. So I tried:

    add_image_size(‘450-wide’, 450, 9999);

    Same result for all three: in Edit Post > Add Media, the names of the new image sizes are coming up, but the sizes themselves have been shrunk. It seems that somewhere else, the maximum image width has been defined as 660px and this is overriding the php. See this screen shot to see what I mean.

    Leo

    (@leowebdev)

    Simple like that!

    Create the file functions.php on your child theme folder Ex. “mytheme-child” and white the php command below:

    include_once THEME_DIR.’../mytheme/functions.php’;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Functions.php in child theme’ is closed to new replies.