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 haven’t 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]
2 s
to read the attribut country
, you just need to read it in $atts
add_shortcode( 'ifurl', 'ifurl' );
function ifurl($atts, $content = null) {
$url="https://" . $_SERVER['SERVER_NAME'];
$current_tld = end(explode(".", parse_url($url, PHP_URL_HOST)));
if ($current_tld === $atts["country"]) {
return $content;
}
};