How7o
  • Home
  • Marketing
    MarketingShow More
  • OS
    OSShow More
    How to force quit frozen apps in Ubuntu
    Force Close an App in Ubuntu (xkill, System Monitor, kill -9)
    4 Min Read
  • Features
    FeaturesShow More
  • Guide
    GuideShow More
  • Contact
  • Blog
Reading: How to Dynamically Set Site Title and Tagline in WordPress (By Country)
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Categories
    • Marketing
    • OS
    • Features
    • Guide
    • Lifestyle
    • Wellness
    • Healthy
    • Nutrition
  • More Foxiz
    • Blog Index
    • Complaint
    • Sitemap
    • Advertise
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > Web Development > How to Dynamically Set Site Title and Tagline in WordPress (By Country)
Web Development

How to Dynamically Set Site Title and Tagline in WordPress (By Country)

how7o
By how7o
Last updated: February 6, 2026
6 Min Read
Dynamically set site title and tagline in WordPress by country
SHARE

I recently faced a problem where I needed to dynamically set site title and tagline in WordPress based on the visitor’s country. The default Site Title and Tagline in Settings → General are global, but my site served different regions (USA, UK, etc.), and I wanted the branding to change automatically on every page load.

Contents
  • What we’re actually changing (and what we’re not)
  • My solution: filter blogname and blogdescription by country
  • Step-by-step: add the code to WordPress
    • Step 1: Add the filters
    • Step 2: Detect the country
    • Step 3: Dynamically set the Site Title
    • Step 4: Dynamically set the Tagline
  • Optional: support more countries (cleaner mapping)
  • Important notes (SEO + caching)
  • Troubleshooting
    • The Site Title or Tagline doesn’t change

After digging into how WordPress stores and outputs these values, I found a clean solution: hook into the option_blogname and option_blogdescription filters and return a country-specific version of the text.

What we’re actually changing (and what we’re not)

WordPress stores the Site Title and Tagline in the database as options: blogname and blogdescription. If you change them in the admin area, you’re updating the saved values.

But in many cases, you don’t want to overwrite your database values per visitor. You just want WordPress to output a different title/tagline depending on conditions (country, language, subdomain, etc.). That’s exactly what these filters do: they let you intercept the option value right before WordPress uses it.

My solution: filter blogname and blogdescription by country

The approach is simple:

  • Detect the visitor’s country (however you prefer).
  • Hook into option_blogname and option_blogdescription.
  • Return custom text when the country matches your rules.

Step-by-step: add the code to WordPress

You can place this in your theme’s functions.php file. If you want a safer, update-proof option, add it using the Code Snippets plugin or a small custom plugin. (Same code either way.)

Step 1: Add the filters

add_filter( 'option_blogname', 'my_change_blogname_by_country' );
add_filter( 'option_blogdescription', 'my_change_blogdescription_by_country' );

Step 2: Detect the country

You’ll need to define how you determine $country. The most common options are:

  • Cloudflare (recommended): use the CF-IPCountry header if your site is behind Cloudflare.
  • Server-side GeoIP (like MaxMind GeoLite2): more work, but very reliable when configured correctly.
  • User-selected country stored in a cookie/session (best if you allow manual switching).

Below is an example that supports both Cloudflare and a fallback cookie. Adjust to match your setup.

function my_get_visitor_country_code() {
    // 1) Cloudflare country code (e.g., "US", "GB")
    if ( ! empty( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) {
        return strtoupper( sanitize_text_field( $_SERVER['HTTP_CF_IPCOUNTRY'] ) );
    }

    // 2) Optional: country stored in a cookie (e.g., "US", "GB")
    if ( ! empty( $_COOKIE['site_country'] ) ) {
        return strtoupper( sanitize_text_field( $_COOKIE['site_country'] ) );
    }

    // 3) Default fallback
    return 'US';
}

Step 3: Dynamically set the Site Title

function my_change_blogname_by_country( $text ) {
    $country = my_get_visitor_country_code();

    if ( $country === 'US' ) {
        $text = 'Jobs in USA';
    } elseif ( $country === 'GB' ) {
        $text = 'Jobs in UK';
    }

    return $text;
}

Step 4: Dynamically set the Tagline

function my_change_blogdescription_by_country( $text ) {
    $country = my_get_visitor_country_code();

    if ( $country === 'US' ) {
        $text = 'Best Jobs in United States';
    } elseif ( $country === 'GB' ) {
        $text = 'Best Jobs in United Kingdom';
    }

    return $text;
}

That’s it. Now your WordPress site will output different Site Title and Tagline values based on country—without changing anything in Settings → General.

Optional: support more countries (cleaner mapping)

If you plan to support many regions, a mapping array is easier to manage than a long list of elseif statements.

function my_site_branding_map() {
    return array(
        'US' => array(
            'name' => 'Jobs in USA',
            'desc' => 'Best Jobs in United States',
        ),
        'GB' => array(
            'name' => 'Jobs in UK',
            'desc' => 'Best Jobs in United Kingdom',
        ),
        // Add more: 'CA', 'AU', 'DE', etc.
    );
}

function my_change_blogname_by_country( $text ) {
    $country = my_get_visitor_country_code();
    $map     = my_site_branding_map();

    if ( isset( $map[ $country ]['name'] ) ) {
        $text = $map[ $country ]['name'];
    }

    return $text;
}

function my_change_blogdescription_by_country( $text ) {
    $country = my_get_visitor_country_code();
    $map     = my_site_branding_map();

    if ( isset( $map[ $country ]['desc'] ) ) {
        $text = $map[ $country ]['desc'];
    }

    return $text;
}

Important notes (SEO + caching)

  • Page caching: If you use a full-page cache (plugin, host cache, Cloudflare cache), it may serve the same cached HTML to everyone. In that case, your dynamic title/tagline might look “stuck.” You’ll need cache variation by country (or disable caching for pages where it matters).
  • Search engines: If search bots see different titles based on location, results may vary by region. That can be fine for local targeting, but make sure it’s intentional.
  • Theme usage: Most themes display the Site Title/Tagline in the header and use them in various template parts. With these filters, you’re changing what WordPress returns everywhere it calls those options.

Troubleshooting

The Site Title or Tagline doesn’t change

  • Temporarily disable caching (plugin/server/CDN) and refresh.
  • If you’re using Cloudflare, co
TAGGED:filtersfunctions.phpgeolocationhookslocalizationoption_blogdescriptionoption_blognamesite titletaglinewordpress

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Capitalize all words in JavaScript with a ucwords-style function Capitalize All Words in JavaScript (ucwords Equivalent) + First Letter Uppercase
Next Article Find prime numbers in JavaScript thumbnail How to Find Prime Numbers in JavaScript (1 to 100) — Fast & Simple Methods
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Find prime numbers in JavaScript thumbnail
How to Find Prime Numbers in JavaScript (1 to 100) — Fast & Simple Methods
February 6, 2026
Dynamically set site title and tagline in WordPress by country
How to Dynamically Set Site Title and Tagline in WordPress (By Country)
February 6, 2026
Capitalize all words in JavaScript with a ucwords-style function
Capitalize All Words in JavaScript (ucwords Equivalent) + First Letter Uppercase
February 6, 2026
CSS page break for printing shown in a print preview layout
CSS Page Break for Printing: How to Split a Web Page Into Multiple Printed Pages
February 6, 2026
get .env variable in Laravel using env and config
How to Get .env Variables in Laravel (Controller + Blade) Safely
February 6, 2026

You Might Also Like

Include Composer packages in plain PHP projects
Web Development

How to Include Composer Packages in Plain PHP Projects (Autoload + Example)

5 Min Read
Laravel Blade Time Format (HH:MM)
Web Development

How to Show Only Hours and Minutes in Laravel Blade (HH:MM)

3 Min Read
Configure Nginx for WordPress in aaPanel (fix 404 permalinks)
Server Management

Configure Nginx for WordPress in aaPanel (Fix Permalink 404 Errors)

5 Min Read
Check if GD library is installed in PHP (phpinfo and extension_loaded)
Web Development

How to Check if GD Library Is Installed in PHP (3 Easy Methods)

5 Min Read

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?