WordPress.org

Ready to get started?Download WordPress

Forums

Modify Widget Titles (3 posts)

  1. Greg Dietrich
    Member
    Posted 1 year ago #

    I want the titles of my widgets to style like this, http://files.gadietrich.com/widget_yes.png. In this example I am using a Text widget without a title, but putting this code in the main box:

    <h3><span class="home_widget"><span class="home_widget_lc">join us</span> on sundays</span></h3>

    This won't work though if I am using other widgets. So how can I get this type of display with any of my widgets using the title. I am guessing I might have to add another title field, however, I'm clueless on that.

    The site I am working on is http://clients.gadietrich.com/prov

  2. codescribblr
    Member
    Posted 1 year ago #

    try this:

    add_filter('widget_title', 'custom_widget_title', 10, 1);
    function custom_widget_title($title){
    	$title_array = explode(" ", $title);
    	$count = count($title_array);
    	if($count==1){
    		$title = '<span class="home_widget">' . $title . '</span>';
    	} elseif($count==2){
    		$title = '<span class="home_widget"><span class="home_widget_lc">' . $title_array[0] . '</span> ' . $title_array[1] . '</span>';
    	} elseif($count==3){
    		$title = '<span class="home_widget"><span class="home_widget_lc">' . $title_array[0] . ' ' . $title_array[1] . '</span> ' . $title_array[2] . '</span>';
    	} elseif($count>=4){
    		foreach($title_array as $word_number => $word){
    			if($word_number <= 1){continue;}
    			$remaining_words .= ' ' . $word;
    		}
    		$title = '<span class="home_widget"><span class="home_widget_lc">' . $title_array[0] . ' ' . $title_array[1] . '</span>' . $remaining_words . '</span>';
    	}
    	return $title;
    }
  3. Greg Dietrich
    Member
    Posted 1 year ago #

    Where do I put this?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.