From a client's point of view, when the Custom Logo feature is provided, changing the logo of a site is really simple. That was the point of the element all things considered. To use the custom logo feature you need to declare it. This is the reason why this feature is not given by default. We have to define our own function to show the custom logo feature. If we do not define it then the custom logo will not be displayed.
To define this function for the Custom Logo feature we use the add_theme_support()
function. The best way to do this is using a callback function and the after_setup_theme
action. You are using to define the custom logo feature by adding this following code in the functions.php
file of your theme.
function theme_prefix_setup() {
add_theme_support( 'custom-logo' );
}
add_action( 'after_setup_theme', 'theme_prefix_setup' );
It have five parameters which are defined below:
- height - it must be in integer (int) .It is the logo height in pixels that the users wants.
- flex-width- it must be in boolean. It is to be used allow flexible width.
- width - it must be in integer (int) .It is the logo width in pixels that the users wants.
- flex-height- it must be in boolean. It is to be used allow flexible height.
add_theme_support( 'custom-logo', array(
'height' => 200,
'width' => 600,
'flex-width' => true,
) );
- header
-text
(array) is used for hiding the class names. This parameter is only important for those themes that do not provide hiding the header text. Themes can pass a variety of class names here for all components constituting header message that could be changed by a logo
add_theme_support( 'custom-logo', array(
'header-text' => array( 'site-title', 'site-description' ),
) );
To show a custom logo in the front-end, these three layout labels can be utilized:
- get_custom_logo ($blog_id=0)- With the help of this the markup of the custom logo is seen.
- the_custom_logo ($blog_id=0)- With the help of this the markup of the custom logo is seen.
- has_custom_logo ($blog_id=0)- To check whether the custom logo is set or not we use this function. It return the value in true or false.
<?php
// Display the Custom Logo
the_custom_logo();
// No Custom Logo, just display the site's name
if (!has_custom_logo()) {
?>
<h1><?php bloginfo('name'); ?></h1>
<?php
}
?>
To show if the function exists we use the following code.
function mytheme_custom_logo() {
// Try to retrieve the Custom Logo
$output = '';
if (function_exists('get_custom_logo'))
$output = get_custom_logo();
// Nothing in the output: Custom Logo is not supported, or there is no selected logo
// In both cases we display the site's name
if (empty($output))
$output = '<h1><a href="' . esc_url(home_url('/')) . '">' . get_bloginfo('name') . '</a></h1>';
echo $output;
}
0 Comment(s)