Support » Plugins » Can somebody please tell me how to use the bloginfo filter?

  • Resolved walterego

    (@walterego)


    Hey guys,

    hoping some plugin guru can help me out. I’m just starting out writing plugins and right now I’m doing on that needs to replace the bloginfo(‘description’) with another string. I just can’t get around how to do this though.

    <?php
    function replace_description($bloginfo) {
    	$descriptionreplacement = "A string";
    	$bloginfo['description'] = $descriptionreplacement;
    	return $bloginfo;
    }
    ?>

    I get really strange results with this, when using this specific example I get a replaced title and description, but only the first letter of it is changed, it’s an A now (Aust another WordPress weblog).

    When simply replace $bloginfo it does replace correctly, but everything is replaced (including title). Anybody can help?

    Walter

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    In a filter, all that usually matters is what you return. You don’t have to set $bloginfo[] to anything.

    function your_function($info, $show) {
    // do something to $info
    return $info;
    }
    add_filter('bloginfo','your_function',10,2);

    The $show variable will be what they are trying to get. Like ‘description’.

    So your code should be like this:

    <?php
    function replace_description($info, $show) {
      if ($show == 'description') {
        // do something to $info
      }
    return $info;
    }
    add_filter('bloginfo','replace_description',10,2);
    ?>

    Note that some of these bloginfo things have been replaced with options values, and so working there would be a better idea. The ‘description’ is one of these, it’s an option called ‘blogdescription’. You could more easily modify it like so:

    function replace_description($description) {
    // do something to $description
    return $description;
    }
    add_filter('option_blogdescription','replace_description');

    No need for any checking of any kind. It’s faster too, since it’s not called for every single bloginfo call.

    Thread Starter walterego

    (@walterego)

    Great! Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can somebody please tell me how to use the bloginfo filter?’ is closed to new replies.