WordPress.org

Ready to get started?Download WordPress

Forums

get_bloginfo() second parameter, $filter ??? (5 posts)

  1. arteedecco
    Member
    Posted 3 years ago #

    So I am new to WP in general as well as developing themes, child-themes, templates, etc.

    I am going through the twentyten theme and noticed that in the header.php file there is a call to get_bloginfo( 'name', 'display' ) and then just a few characters later there's a call to bloginfo( 'name' ).

    It is confusing, first off, to me that there are two functions for getting blog info that essentially take similar parameters and return essentially similar data, just in different formats.

    What made this journey for understanding all the more 'Alic in Wonderland'-esque was the seemingly undefined second parameter being passed to get_bloginfo: 'display'.

    The code I'm speaking of in header.php is (starting on line 50, I believe):

    <span>
      <a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
    </span>

    I understand that get_bloginfo is called first because another php function is being used on the returned string data, making the use of bloginfo impossible. However, what is the purpose of the second paramter sent to that function, 'display'.

    Looking at the general WP codex function def for get_bloginfo it is not defined or mentioned at all.
    ref. located here: http://codex.wordpress.org/Function_Reference/get_bloginfo

    However, there is reference to the mystery second parameter in the WPMU codex here: http://codex.wordpress.org/WPMU_Functions/get_bloginfo
    The WPMU codex for this function is wanting for a description of the possible values of the $filter second parameter, other than the default 'raw'.

    I'm assuming that the writers of the twentyten theme used the second parameter out of old WPMU habit, rather than actual necessity? In tests I've run I have been unable to see any effect of the second parameter. If this is just a carryover from WPMU, is there any validity to passing the second parameter?

    Is there documentation I'm missing on template tags and general acceptance of an optional second parameter?

    Help!? I have to know or I won't sleep! :)

    Thanks!

    Love what you're doing here!

  2. dashaluna
    Member
    Posted 3 years ago #

    Hello I'm a newbie to WP as well. Just started to poke around 2010.

    Would be good if anyone will let us (all newbies) know what that 'display' param does? As @arteedecco said there aren't much in the docs.

    Thanks :)

  3. Spencer Finnell
    Member
    Posted 3 years ago #

    It allows you to apply a filter to the ouput data.

    if ( 'display' == $filter ) {
    	if ( $url )
    		$output = apply_filters('bloginfo_url', $output, $show);
    	else
    		$output = apply_filters('bloginfo', $output, $show);
    }

    If you look at the source you can see the steps it goes through.

    get_bloginfo() passes the filter argument as 'raw', by default, so if you still want to be able to filter get_bloginfo() you need to pass 'display' as the filter argument. When you just call bloginfo() next to it, bloginfo() passes filter as 'display' by default, so it's not needed.

  4. dashaluna
    Member
    Posted 3 years ago #

    @SpencerFinnell thanks for the reference, I had a look at the function. As far as I understand the $filter can only be of 2 values: 'raw' (the default) and 'display'.

    When the 'display' filter is supplied does it mean that either "bloginfo_url" or "bloginfo" functions will be called with $output and $show params? If so, then, for example, the bloginfo() simply echos the $show param:

    function bloginfo( $show='' ) {
     echo get_bloginfo( $show, 'display' );
    }

    So, I'm still pretty much confused how the 'display' filter affects what the get_bloginfo() returns :(

    Sorry for being so slow, but I am genuenly confused. Would appreciate some help with it :)

    Thanks
    Dasha

  5. saltlakejohn
    Member
    Posted 2 years ago #

    For years the standard has been: use "get_bloginfo" to fill a variable, like this: $var = get_bloginfo('name'). Then you have a string you can work with before sending it to the screen. That lets us do something like this: echo strtoupper($var).

    Otherwise, if all we need is to get the name on the screen, bloginfo('name') outputs text immediately, right at that point in the template.

    The fact that "bloginfo" is built on top of "get_bloginfo" plus a 'display' parameter has never been real important. Providing two different function words helps beginners learn and helps oldsters read and maintain code faster and more accurately.

    Other "get_" functions follow suit. The pattern is the same for get_the_author and the_author. Same also for the_permalink and get_permalink. Consistent, you see, to reduce errors and shorten the learning curve.

    WordPress default themes have always used many WP functions so as to show off a variety of WP capabilities. The TwentyTen theme is also meant to be instructional -- it's meant to impart knowledge, if not wisdom.

    TwentyTen has many more template files and uses more programatic twiddles than any small, simple theme would want. That's intentional because TwentyTen is, first, a well-designed learning tool. Secondly, it is meant to form a strong foundation for child themes, and the new thing WordPress is pushing now is the concept of child-theme design. Wise and wondrous are the WP developers.

    WordPress has always developed faster than the code documentation could keep up with. The program (all programs, perhaps) attract coders more readily than technical writers. Probably because there is always a dearth of people with a technical bent who can also write well.

Topic Closed

This topic has been closed to new replies.

About this Topic