Skip to content

alexwcoleman/WordPress-Custom-Logo-Data-Attributes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

WordPress Custom Logo Data Attributes

nothing much to see here... just like the title says.

The path for the image can be anything. The only reason I did it outside of WP is to keep the images away from the uploader so the client & employees would have a harder time deleting it.

/**
 * Add data attributes to the custom logo.
 */
add_filter( 'wp_get_attachment_image_attributes', function ( $attr ) {
 
    if ( isset( $attr['class'] ) && 'custom-logo' === $attr['class'] ) {
        $attr['data-small-logo'] = '/path/to/small/image.jpg';
        // or this way
        // $attr['data-small-logo'] = get_template_directory_uri() . '/path/to/small/image.jpg';

        $attr['data-medium-logo'] = '/path/to/medium/image.jpg';
        // or this way
        // $attr['data-medium-logo'] = get_template_directory_uri() . '/path/to/medium/image.jpg';
    }
 
    return $attr;
} );
	

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages