Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

annag on "GeoTargeting PHP code for Custom Fields"

$
0
0

I altered my single post page PHP to make the featured image link to an external link. I would now like to take that a step further and send it to a different link depending on the user's country of origin. I am using Flytonic's Geotarget plugin for geotargeting.

Currently the code looks like this to send the featured image to an external link:

<?php $name = get_post_meta($post->ID, 'url-for-featured-image', true); ?>
			<div class="post-media">
				<a>"><?php
				// Display media (Video URL >> Wide embed >> Embed >> Image)
				if($vid_url):
		        	echo apply_filters( 'the_content', "[embed width='670']" . $vid_url . "[/embed]" );
		        elseif($vid_wide):
					echo $vid_wide;
		        elseif($vid):
					echo $vid;
				elseif ( has_post_thumbnail() ):
		            the_post_thumbnail('col4', array( 'class' => 'feat-img' ) );

		        endif; ?></a>

In order to change that first line:

<?php $name = get_post_meta($post->ID, 'url-for-featured-image', true); ?>

so that it changes to "uk-url-for-featured-image" if the user is coming from the UK, what should I add? Please note that I am totally new to PHP and WordPress (having used Movable Type for years) so please don't be too hard on me if what I am asking is impossible!

Flytonic's documentation says to use this code to change PHP code based on geotargeting.

<?php if (function_exists(‘fgeo_target’) && fgeo_target(‘uk’)==true) : ?>
YOUR CODE
<?php endif; ?>

I tried wrapping that code around the above code like this but it didn't work:

<?php if (function_exists(‘fgeo_target’) && fgeo_target(‘uk’)==true) : ?>
<?php $name = get_post_meta($post->ID, 'uk-url-for-featured-image', true); ?>
			<div class="post-media">
				<a>"><?php
				// Display media (Video URL >> Wide embed >> Embed >> Image)
				if($vid_url):
		        	echo apply_filters( 'the_content', "[embed width='670']" . $vid_url . "[/embed]" );
		        elseif($vid_wide):
					echo $vid_wide;
		        elseif($vid):
					echo $vid;
				elseif ( has_post_thumbnail() ):
		            the_post_thumbnail('col4', array( 'class' => 'feat-img' ) );

		        endif; ?></a>
<?php endif; ?>

What am I doing wrong?


Viewing all articles
Browse latest Browse all 8245

Trending Articles