WordPress.org

Ready to get started?Download WordPress

Forums

PHP link (2 posts)

  1. SerenadeWebDesign
    Member
    Posted 1 year ago #

    There's a social media widget on the footer of my template (http://www.lastkeyrealty.com/wordpress/), I want to change the "stay in touch" title to be a link that opens in a new window, I believe it's the "$title" in the code, how do I do this, here is the code:

    function My_SocialNetworksWidget() {
    		$widget_ops = array('classname' => 'social_networks_widget', 'description' => __('Link to your social networks.'));
    		$this->WP_Widget('social_networks', __('My - Social Networks'), $widget_ops, $control_ops);
    	}
    
    	function widget( $args, $instance ) {
    		extract($args);
    		$title = apply_filters('widget_title', $instance['title']);
    
    		$networks['Twitter']['link'] = $instance['twitter'];
    		$networks['Facebook']['link'] = $instance['facebook'];
    		$networks['Tumblr']['link'] = $instance['tumblr'];
    		$networks['Pinterest']['link'] = $instance['pinterest'];
    
    		$networks['Twitter']['label'] = $instance['twitter_label'];
    		$networks['Facebook']['label'] = $instance['facebook_label'];
    		$networks['Tumblr']['label'] = $instance['tumblr_label'];
    		$networks['Pinterest']['label'] = $instance['pinterest_label'];
    
    		$display = $instance['display'];
    
    		echo $before_widget;
    		if ( $title )
        		echo $before_title . $title . $after_title;
    		?>
  2. vtxyzzy
    Member
    Posted 1 year ago #

    You can use the widget_title filter to modify the title. Add the code below to your child theme's functions.php file. But be careful. If you cause an error, you must use ftp or a File Manager from your hosting service to correct it.

    // Filter to make Social Network Widget's title a link
    add_filter('widget_title','mam_widget_title_filter');
    function mam_widget_title_filter($title) {
       $social_network_title = 'Test widget';  // Put your title here
       $url = 'http://localhost/test/articles/cities/';  // Put your URL here
    
       $new_title = $title;
       if ($title == $social_network_title) {
          $new_title = "<a href='$url'>$title</a>";
       }
       return $new_title;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic