Function and usage of get_bloginfo() in wordpress

Question

Answers ( 1 )

    0
    2024-01-06T16:06:26+00:00

    The get_bloginfo() function in WordPress is a versatile function that retrieves various pieces of information about the current site. This function is often used in themes and plugins to access site details programmatically.

    Function Syntax

    get_bloginfo( string $show = '', string $filter = 'raw' ): string
    

    Parameters

    1. $show (string, optional): Specifies the type of information you want to retrieve about the site. The default value is an empty string, which typically returns the site name.
    2. $filter (string, optional): Determines how the retrieved information is filtered. The default value is 'raw', meaning the information is returned as it is stored in the database.

    Description

    The get_bloginfo() function can return various types of information depending on the value passed to the $show parameter. Some of the common values for $show include:

    • 'name': Retrieves the site title as set in Settings > General.
    • 'description': Gets the site tagline from Settings > General.
    • 'wpurl': The WordPress address (URL) set in Settings > General.
    • 'url': The Site address (URL) set in Settings > General.
    • 'admin_email': The admin email address from Settings > General.
    • 'charset': The encoding for pages and feeds set in Settings > Reading.
    • 'version': The current WordPress version.
    • 'html_type': The Content-Type, default is "text/html".
    • 'text_direction': The text direction based on the site's language.
    • 'language': The language code for the current site.
    • 'stylesheet_url': URL to the stylesheet for the active theme.
    • 'stylesheet_directory': Directory path for the active theme.
    • 'template_url'/'template_directory': URL of the active theme’s directory.
    • 'pingback_url': The pingback XML-RPC file URL.
    • 'atom_url': The Atom feed URL.
    • 'rdf_url': The RDF/RSS 1.0 feed URL.
    • 'rss_url': The RSS 0.92 feed URL.
    • 'rss2_url': The RSS 2.0 feed URL.
    • 'comments_atom_url': The comments Atom feed URL.
    • 'comments_rss2_url': The comments RSS 2.0 feed URL.

    Deprecated Arguments

    Some $show values are deprecated and will trigger the _deprecated_argument() function. These include:

    • 'siteurl': Deprecated. Use 'url' instead.
    • 'home': Deprecated. Use 'url' instead.

    Return Value

    The function mostly returns string values, but it might return an empty string depending on the site configuration and the requested information.

    Sample Usage

    // Retrieve the site name
    $site_name = get_bloginfo( 'name' );
    
    // Get the WordPress version
    $wp_version = get_bloginfo( 'version' );
    
    // Retrieve the URL of the active theme's stylesheet
    $stylesheet_url = get_bloginfo( 'stylesheet_url' );
    

    In these examples, get_bloginfo() is used to fetch the site name, the WordPress version, and the URL of the active theme's stylesheet, demonstrating its flexibility and usefulness in theme and plugin development.

Leave an answer