WordPress.org

Forums

Basic Plugin Question (5 posts)

  1. fncll
    Member
    Posted 9 years ago #

    OK, so I know I can write a plugin that has the code:

    add_filter('bloginfo', 'strtoupper');

    and all the bloginfo content will be set to uppercase (blog title, description, etc).

    But how do I change something specific, for instance what if I wanted *only* the description from bloginfo to be uppercase?

  2. Joshua Sigar
    Member
    Posted 9 years ago #

    function toUpperBlogDescription($info, $show) {
    if ($show == 'blogdescription') {
    $info = strtoupper($info);
    }
    return $info;
    }

    add_filter('bloginfo', 'toUpperBlogDescription')

    Off the top of my head, something like that minus the error if any.

  3. fncll
    Member
    Posted 9 years ago #

    This gives an error looking for the second argument for toUpperBlogDescription...

    I'm not sure if this code actually is doing what I am wanting to do, which is change the specific call to bloginfo('description') rather than every instance of the bloginfo() function (which is built-in to PHP)

  4. Joshua Sigar
    Member
    Posted 9 years ago #

    function toUpperBlogDescription($info, $show) {
    if ($show == 'description') {
    $info = strtoupper($info);
    }
    return $info;
    }

    //add_filter('filter_name', 'filter_func', priority, number of arguments)
    add_filter('bloginfo', 'toUpperBlogDescription', 10, 2);

    The filter function toUpperBlogDescription is indeed invoked for every call to bloginfo; however, only if you retrieve the description then the output is converted to uppercase.

  5. fncll
    Member
    Posted 9 years ago #

    Thanks! That did it. That last parameter when you call add_filter (the number of arguments) wasn't shown on the wiki pages I was using... and it of course makes all the difference :)

    I'm going to fix/update the wiki pages when I go back.

Topic Closed

This topic has been closed to new replies.

About this Topic