Support » Fixing WordPress » External image link linking to same domain

  • Resolved willsreniu

    (@willsreniu)


    I am trying to code so that a form entry is used to create a link for the thumbnail, but the link is linking to within the websites domain:( so if my site is google.com and submit the form to link to gerad.tv it goes to http://www.google.com/gerad.tv, but I just want it to go to gerad.tv) I think something is wrong with this code, but I’m not sure what.

    function my_post_image_html( $html, $post_id, $post_image_id ) {
    	$external_link = get_post_meta( get_the_ID(), 'ap_author_url', true );
    				if ( ! empty($external_link ) && !is_feed() && !is_home() && in_category('user') ) {
    					$html = '<a href="' . $external_link . '" target="_blank">' . $html . '</a>';
    					}else{
    	$html = '<a href="' . get_permalink( $post_id ) .'" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
    	}
    	return $html;
    
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Well, you’ll need to add in an http:// somewhere so that the browser knows it’s a separate URL – otherwise it assumes it’s a relative link and tries to go to it within the current domain.

    So you either need to include the http:// when you submit the form, like http://gerard.tv, or you need to change this line to include the http:// like so:

    $html = '<a href="http://' . $external_link . '" target="_blank">' . $html . '</a>';

    (and then make sure you don’t put the http:// in when you submit the form!)

    Thread Starter willsreniu

    (@willsreniu)

    Awesome, I forgot about http:// Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘External image link linking to same domain’ is closed to new replies.