How do I create a Shortcode that returns text if domain is .com, not .co.uk

I am trying to create a shortcode to see if the url matches with the attribute, then return the content. So far I have:

add_shortcode( ‘ifurl’, ‘ifurl’ );

function ifurl($atts, $content = null) {
$url = ‘https://’ . $_SERVER[‘SERVER_NAME’];
$current_tld = end(explode(“.”, parse_url($url, PHP_URL_HOST)));
$country_select = // Something to get attribute ‘country’

if ($current_tld == $country_select) {
return $content
}
};

But as you can see I havnt been able to get the attributes to work correctly, and the if statement.

I would like to use it like this:

[ifurl country=”com”] Show only if .com [/ifurl]

[ifurl country=”uk”] Show only if .co.uk [/ifurl]

Read more here:: How do I create a Shortcode that returns text if domain is .com, not .co.uk

Leave a Reply

Your email address will not be published. Required fields are marked *