• I’m new to PHP so can you help me? I have template for wordpress, and use visual composer. There’s “team member” option in this template, and then you edit it there’s a option to insert social links which I will not use for social links. So, what I want to do on live web is: Then I press on team member image it uses twitter link which I inserted in edit (in visual composer). I believe it’s simple, but for me(new guy in php) it’s a little bit hard. Thanks in advance!

    GOAL: Force team member image to use twitter link.

    Here’s code:

    <?php
    $atts = shortcode_atts( array(
    	'class'    => '',
    	'css'      => '',
    	
    	'name'     => 'John Doe',
    	'subtitle' => '',
    	'image'    => '',
    
    	'facebook' => '',
    	'twitter'  => '',
    	'linkedin' => '',
    	'google'   => '',
    	''
    ), $atts );
    
    $member_image = '';
    $member_info  = sprintf( '<h3 class="member-name">%s</h3>', esc_html( $atts['name'] ) );
    $class        = array( 'member', $atts['class'] );
    
    if ( ! empty( $atts['image'] ) ) {
    	if ( is_numeric( $atts['image'] ) && $images = wp_get_attachment_image_src( $atts['image'], 'full' ) )
    		$atts['image'] = array_shift( $images );
    
    	$class[] = 'has-image';
    	$member_image = sprintf( '
    		<div class="member-image">
    			<img src="%s" alt="%s" />
    		</div>
    	', esc_attr( $atts['image'] ), esc_attr( $atts['name'] ) );
    }
    
    if ( ! empty( $atts['subtitle'] ) )
    	$member_info.= sprintf( '<div class="member-subtitle">%s</div>', wp_kses_post( $atts['subtitle'] ) );
    
    $social_links = '';
    $content = force_balance_tags( wpautop( $content ) );
    $content = preg_replace( '/<([a-z]+)>\s*<\/\\1>/i', '', $content );
    
    if ( ! empty( $atts['facebook'] ) )
    	$social_links.= sprintf( ' <a href="%s" data-title="Facebook" class="facebook"><i class="fa fa-arrow-right"></i></a>', esc_url( $atts['facebook'] ) );
    
    if ( ! empty( $atts['twitter'] ) )
    	$social_links.= sprintf( ' <a href="%s" data-title="Twitter" class="twitter"><i class="fa fa-twitter"></i></a>', esc_url( $atts['twitter'] ) );
    
    if ( ! empty( $atts['linkedin'] ) )
    	$social_links.= sprintf( ' <a href="%s" data-title="LinkedIn" class="linkedin"><i class="fa fa-linkedin"></i></a>', esc_url( $atts['linkedin'] ) );
    
    if ( ! empty( $atts['google'] ) )
    	$social_links.= sprintf( ' <a href="%s" data-title="Google Plus" class="google-plus"><i class="fa fa-google-plus"></i></a>', esc_url( $atts['google'] ) );
    
    if ( ! empty( $social_links ) )
    	$social_links = sprintf( '<div class="social-links">%s</div>', $social_links );
    
    printf( '
    	<div class="%s">
    		%s
    		<div class="member-info">
    			%s
    			<div class="member-desc">%s</div>
    		</div>
    		%s
    	</div>', 
    	esc_attr( implode( ' ', $class ) ),
    	$member_image,
    	$member_info,
    	$content,
    	$social_links
    );
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Just wrap the img tag output (within its div) in an anchor tag whose destination is the twitter attribute. This is only tricky because of the sprintf() structure. Change it to this:

    	$member_image = sprintf( '
    		<div class="member-image">
    			<a href="%s" >
    				<img src="%s" alt="%s" />
    			</a>
    		</div>
    	', esc_url( $atts['twitter'] ), esc_attr( $atts['image'] ), esc_attr( $atts['name'] ) );
    }

    The link will only work if the twitter URL is passed as a shortcode attribute. I believe this is all internal to VC, so it’s probably handled correctly, provided the URL is available at all.

    Thread Starter rksmartus

    (@rksmartus)

    Thanks for help, but it didnt worked…

    Moderator bcworkz

    (@bcworkz)

    Sorry to hear that. It was a dirty hack anyway, it’s not the best practice to alter plugin code. Is there by any chance an apply_filters() call further down that affects output?

    You may be better off asking VC support about this.

    If all else fails, if the twitter URL exists on the page somewhere, you could use jQuery to grab that URL and make the image into a link element.

    Thread Starter rksmartus

    (@rksmartus)

    I’m thinking about jquery, I think I just don’t waste trying. Anyway, thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Image PHP link’ is closed to new replies.