Generating social media links I'm building an option panel for a Wordpress theme. I'm just learning PHP and I wonder if there is any better (shorter) way to generate the social media links. Here's what I came up with and even tho it works, I think there are cleaner way to write it

&lt;ul&gt;
&lt;?php if ( of_get_option('mm_sm_vimeo') ) { ?&gt;
&lt;li&gt;
&lt;a href="&lt;?php echo of_get_option('mm_sm_vimeo'); ?&gt;"&gt;&lt;img src="&lt;?php echo  get_template_directory_uri(); ?&gt;/images/socials/ico_vimeo.png" alt="Vimeo"/&gt;&lt;/a&gt;&lt;span&gt;Vimeo&lt;/span&gt;
&lt;/li&gt;
&lt;?php } ?&gt;

&lt;?php if ( of_get_option('mm_sm_gplus') ) { ?&gt;
&lt;li&gt;
&lt;a href="&lt;?php echo of_get_option('mm_sm_gplus'); ?&gt;"&gt;&lt;img src="&lt;?php echo get_template_directory_uri(); ?&gt;/images/socials/ico_gplus.png" alt="Google Plus"/&gt;&lt;/a&gt;&lt;span&gt;Google Plus&lt;/span&gt;
&lt;/li&gt;


Etc... etc... over 20 times.

Maybe a loop or something? The problem is that I have a different Option name for each and I don't know how to handle it.
You could take the common bits out into a function:

&lt;?php
function my_thing($name, $title) {
   if ( of_get_option("mm_sm_$name") ) {
      ?&gt;
      &lt;li&gt;
      &lt;a href="&lt;?php echo of_get_option("mm_sm_$name"); ?&gt;"&gt;&lt;img src="&lt;?php echo  get_template_directory_uri(); ?&gt;/images/socials/ico_&lt;?php echo $name ?&gt;.png" alt="&lt;?php echo $title ?&gt;"/&gt;&lt;/a&gt;&lt;span&gt;&lt;?php echo $title ?&gt;&lt;/span&gt;
      &lt;/li&gt;
      &lt;?
   }
}

my_thing('vimeo', 'Vimeo');
my_thing('gplus', 'Google Plus');
?&gt;