RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.38% (6.14%*) • Home Loan Fixed: 5.44% (6.26%*) • Fixed: 5.44% (6.26%*) • Variable: 5.38% (6.14%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Geographically Relevant Titles in WordPress

Geographically Relevant Titles in WordPress

Did my headline get your attention? The title should have rendered the city you're in or near based on your geographic location. If we couldn't resolve your location it's likely you're seeing the title "Geographically Relevant Titles in WordPress".

While the geographically targeted titles are often used for those spammy dating sites and other ethically challenged web enterprises, they have a very genuine place in online marketing. Certainly, our real-estate and mortgage broker clients that operate Australia-wide have enjoyed a click-through rate over 3 times what they had with a generic title. In my own testing, I've seen conversions of over 600% in some cases when compared against the static alternative.

Geographically Relevant Titles in WordPress

What the post title looks like for me. My title might change...

Why does the CTR increase? People are more likely to click on a post link when the content is personal and relevant. Whatever the purpose, it's almost an absolute assurance that your page visitation will be higher. However, in all cases where you deliver an expectation in a headline, make sure your post honors your geo-based promise. Trickery and click-bait might get a page-view... but it's far less likely to attract genuine brad trust.

The PHP code below utilises our location API to determine a city and country. If the IP can't be resolved, we'll display a static post title instead.

Enable Shortcode in the WordPress Title

Use of shortcodes in the title requires that you enable the_title filter (disabled by default).

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
/* Enable Shortcode in the WP title */
2
add_filter( 'the_title', 'do_shortcode' );

If you're using our custom functions plugin, the filter is enabled by default. If you download our plugin, the above action obviously isn't necessary.

Requirements

  • Get the IP Address of a Visitor with PHP (or WordPress Shortcode) - Download.
  • Simple Cache With PHP - Download (plugin available).

Our plugin will negate the need for the IP function, and prompt you to download the Simple Cache plugin.

The Shortcode function

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

1
<?php 
2
/*
3
 Geographically Relevant Titles
4
 http://www.beliefmedia.com/geographically-targeted-titles
5
 Requires the following:
6
 Requires: http://www.beliefmedia.com/simple-php-cache
7
 Requires: http://www.beliefmedia.com/get-ip-address
8
*/
9
 
10
function beliefmedia_geographic_titles($atts) {
11
 
12
  $atts = shortcode_atts(array(
13
    'title' => 'Geographically Relevant Titles in WordPress',
14
    'geotitle' => 'Marketing For People Living Near',
15
    'geotitle_after' => '- Geo Titles in WordPress',
16
    'cache' => 3600 * 24 * 10
17
  ), $atts);
18
 
19
  /* http://www.beliefmedia.com/get-ip-address */
20
  $atts['ip'] = beliefmedia_ip();
21
 
22
  $ip_transient = 'ip_geotitle_' . md5(serialize($atts));
23
  $cachedresult =  beliefmedia_get_transient($ip_transient, $cache = $atts['cache']);
24
 
25
  if ($cachedresult !== false ) {
26
  $return = $cachedresult;
27
 
28
   } else {
29
 
30
        $data = @file_get_contents('http://api.beliefmedia.com/geo/json.php?ip=' . $atts['ip']);
31
        if ($data !== false) {
32
 
33
               /* Decode response */
34
               $data = json_decode($data, true);
35
 
36
               if ( ($data !== false) && ($data !== null) && ($data['status'] == '200') ) {
37
 
38
                      $cityname = $data['data']['cityname'];
39
                      $countryname = $data['data']['countryname'];
40
                      $return = $atts['geotitle'] . ' ' . $cityname . ' (' . $countryname . ') ' . $atts['geotitle_after'];
41
 
42
               }
43
 
44
        }
45
 
46
   /* If $return, we'll cache data, otherwise cache our default title */
47
   $cachedresult = ($data === false) ? beliefmedia_set_transient($ip_transient, $return = $atts['title']) : beliefmedia_set_transient($ip_transient, $return);
48
 
49
   }
50
 
51
 return ( ($data !== false) && ($cachedresult !== false) ) ? $return : $atts['title'];
52
}
53
add_shortcode('geotitle', 'beliefmedia_geographic_titles');

The shortcode of [geotitle] will render as defined by the attribute of geotitle, geotitle_after, and the location resolved by your IP address.

Shortcode Attributes

The following shortcode attributes are available.

title

The title is a fallback option if your IP address can't be resolved, or the API doesn't respond.

geotitle

The geotitle is the optional first part of your title (before the location).

geotitle_after

The geotitle_after is optional text that comes after your title.

cache

The cache period is the timeframe we'll associate an IP address with location text. By default we'll cache for 10 days. Caching is discussed in more detail below.

Any text you enter into your post title field (from your WordPress editor) will always show.

Post Permalink

Your WordPress Permalink (the slugged URL of your page) obviously won't display shortcode. You must change it so it doesn't include the [geotitle] text. Replace it with anything of your choosing.

Caching

We work on the premise that the majority of visits to your site come from a minority of people. For that reason, we'll associate an IP address with the fully constructed title text and cache it for 10 days (realistically, IP addresses rarely change so it could be far longer). Since we don't want to fill up the database with multiple title records, we require the use of Simple Cache to keep file system records of each IP title (available as a WP plugin).

Considerations

  • Caching is necessary. If you make repeated requests to our API for the same address, we'll either return a slow down error response (429) or lock you out completely.

Download


Title: Geographically Targeted Titles in WordPress (WP Plugin)
Description: Geographically targeted titles. Displays a visitor location in your WordPress post or page title.
  Download • Version 0.2, 2.6K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (824.0B)    

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment