WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode Attributes from Custom Fields (1 post)

  1. rmcneildesign
    Member
    Posted 1 year ago #

    I am working on a site using an Inovado child theme and I have a shortcode that adds a box with a organization member's photo name, website, role, social media info, etc. The shortcode attributes can be edited to specify what photo, name, role, etc. should appear. I want to use this feature to display the organization's officers' information and was hoping to make it possible for the attributes to be edited via custom fields on the "Officers" page. That way the client can just replace an old officer's information with a new one and make the update easily without having to search through all of the short codes. Is this possible?

    Here's the shortcode function from the parent theme shortcodes.php file:

    function minti_member( $atts, $content = null) {
    extract( shortcode_atts( array(
          'img' 	=> '',
          'name' 	=> '',
          'url'		=> '',
          'role'	=> '',
          'twitter' => '',
          'facebook' => '',
          'skype' => '',
          'google' => '',
          'linkedin' => '',
          'mail' => '',
          ), $atts ) );
    
          if($url != '') {
        	$returnurl = "<a href='".$url."'>";
        	$returnurl2 = "</a>";
          } else {
        	$returnurl = "";
        	$returnurl2 = "";
          }
    
          if($img == '') {
        	$return = "";
          } else{
        	$return = "<div class='member-img'>".$returnurl."<img src='".$img."' />".$returnurl2."</div>";
          }
    
          if( $twitter != '' || $facebook != '' || $skype != '' || $google != '' || $linkedin != '' || $mail != '' ){
    	      $return8 = '<div class="member-social"><ul>';
    	      $return9 = '</ul></div>';
    
    	      if($twitter != '') {
    	    	$return2 = '<li class="member-social-twitter"><a href="' .$twitter. '" target="_blank" title="Twitter">Twitter</a></li>';
    	      } else{
    		     $return2 = '';
    	      }
    
    	      if($facebook != '') {
    	    	$return3 = '<li class="member-social-facebook">facebook: <a href="' .$facebook. '" target="_blank" title="Facebook">Facebook</a></li>';
    	      } else{
    		      $return3 = '';
    	      }
    
    	      if($skype != '') {
    	    	$return4 = '<li class="member-social-skype">skype: <a href="' .$skype. '" target="_blank" title="Skype">Skype</a></li>';
    	      } else{
    		      $return4 = '';
    	      }
    
    	      if($google != '') {
    	    	$return5 = '<li class="member-social-google">google+: <a href="' .$google. '" target="_blank" title="Google+">Google</a></li>';
    	      } else{
    		      $return5 = '';
    	      }
    
    	      if($linkedin != '') {
    	    	$return6 = '<li class="member-social-linkedin">linkedin: <a href="' .$linkedin. '" target="_blank" title="LinkedIn">Linkedin</a></li>';
    	      }
    	      else{
    		      $return6 = '';
    	      }
    
    	      if($mail != '') {
    	    	$return7 = '<li class="member-social-email"><a href="mailto:' .$mail. '" title="Mail">Mail</a></li>';
    	      }
    	      else{
    		      $return7 = '';
    	      }
          }  else {
    	      $return2 = '';
    	      $return3 = '';
    	      $return4 = '';
    	      $return5 = '';
    	      $return6 = '';
    	      $return7 = '';
    	      $return8 = '';
    	      $return9 = '';
          }
          return '<div class="member">' .$return. '
          	<h4>' .$name. '</h4>
          	<div class="member-role">' .$role. '</div>' . do_shortcode($content) . '' .$return8. '' .$return2. '' .$return3. '' .$return4. '' .$return5. '' .$return6. '' .$return7. '' .$return9. '</div>';
    }

    The default shortcode from the rich editor button renders as this:

    [member name="John Doe" role="Web Developer" url="http://example.com" img="http://mintithemes.com/nopic.png" twitter="http://twitter.com" facebook="http://facebook.com" skype="http://skype.com" google="http://google.de" linkedin="http://linkedin.com" mail="hellominti@gmail.com"]Description[/member]

    I would like to replace all of those default values with content from custom fields!

    Thank you for any help you can provide!!

    Ryan

Topic Closed

This topic has been closed to new replies.

About this Topic