WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] image from child theme specified in parent theme functions.php (5 posts)

  1. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 4 years ago #

    I have developed a parent theme which will be reused across several sites, each with a custom child theme. I want a login logo for each site which will use a graphic in the images directory in the child theme.

    I have included the following in my functions.php of the parent theme:

    <?php
    // ===== ADD CUSTOM LOGO TO LOGIN
    function my_custom_login_logo() {
        echo '<style type="text/css">
            h1 a { background-image:url('.get_bloginfo('template_directory').'/images/login-logo.png) !important; }
        </style>';
    }
    
    add_action('login_head', 'my_custom_login_logo');
    
    ?>

    However this only works if the login-logo.png is located in the parent theme, but this is not my goal as I want to use a different login-logo.png graphic for each site from the child theme. How can get the functions.php to pull in the graphic from the child theme rather than the parent?

  2. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 4 years ago #

    I found the answer after some more searching.

    Using

    get_bloginfo('stylesheet_directory')

    instead of

    get_bloginfo('template_directory')

    Makes it get the image from the child theme rather than the parent.

  3. mikeward
    Member
    Posted 3 years ago #

    You ALMOST got me where I needed to go. I tried:

    get_bloginfo('stylesheet_directory')

    and it did not work but:

    bloginfo('stylesheet_directory')

    Did.

    Thanks for pointing me in the right direction!

  4. amandafrench
    Member
    Posted 3 years ago #

    Thanks for this. I'm very close to getting it to work; my only problem is that I'm not too familiar with PHP syntax. I have this array in my child theme's functions.php:

    function my_child_theme_setup() {
               register_default_headers( array(
    		'thatcamp-default' => array(
    			'url' => '%s/images/headers/thatcamp-default.png',
    			'thumbnail_url' => '%s/images/headers/thatcamp-default-thumbnail.png',
    			/* translators: header image description */
    			'description' => __( 'THATCamp Default', 'twentyten' )
    		),
    		'thatcamp-purple' => array(
    			'url' => '%s/images/headers/thatcamp-purple.png',
    			'thumbnail_url' => '%s/images/headers/thatcamp-purple.png',
    			/* translators: header image description */
    			'description' => __( 'THATCamp Purple', 'twentyten' )
    		),

    (and so on). I know that I need to replace the placeholder %s, which is currently pointing to the parent theme directory, with either bloginfo('stylesheet_directory') or get_bloginfo('stylesheet_directory') but I'm danged if I can figure out the correct syntax.

  5. amandafrench
    Member
    Posted 3 years ago #

    Aha! I found a great site with exactly the syntax I needed to define a constant and use it in the URL -- I forgot to mention above that we're using Multisite.

    http://wptheming.com/2010/06/wordpress-directory-paths/

Topic Closed

This topic has been closed to new replies.

About this Topic