Generate Wordpress shortcode with attribute. Multi lang url generate with shortcode. add style with shortcode attribute. Add image with shortcode in wordpress. Wordpress shortcode attribute and content.

File : File on themes functions.php

Apply shortcode :

Shortcode is : [language_wise_url en_url="/en/our-locations/" fr_url="/fr/nos-magasins/" de_url="/unsere-filialen/" style="color: #fff; width: 25px; float:left; " img_url="/wp-content/uploads/2021/05/pin.png"]  [/language_wise_url]

Code is : 

// header top store location shortcode  

/*

Maruf Al Bashir 17 may 2021

please upload the pin image first

*/

// [language_wise_url en_url="/en/our-locations/" fr_url="/fr/nos-magasins/" de_url="/unsere-filialen/" style="color: #fff; width: 25px; float:left; " img_url="/wp-content/uploads/2021/05/pin.png"]  [/language_wise_url]

 

function languageWiseUrl($atts, $content = null){

$a = shortcode_atts( array(

'en_url' => '#',

'fr_url' => '#',

'de_url' => '#',

'style' => '',

'img_url' => '',

), $atts );

$the_filter_url =$a['en_url'];

// the site env 

$home_url = get_home_url();

// de [default german]

if($home_url == 'https://staging-ch.laderach.com' || $home_url == 'https://ch.laderach.com'){

$the_filter_url =$a['de_url'];

}

//fr

elseif($home_url == 'https://staging-ch.laderach.com/fr' || $home_url == 'https://ch.laderach.com/fr'){

$the_filter_url =$a['fr_url'];

}

//fr

elseif($home_url == 'https://staging-ch.laderach.com/en' || $home_url == 'https://ch.laderach.com/en'){

$the_filter_url =$a['en_url'];

}

 

 

// end env

$shortcode_style = $a['style'];

// if image

if(!empty($a['img_url'])){

$content = '<img src="'.$a['img_url'].'" alt="location wise url"/>';

}

else{

$content = esc_attr( $content );

}

$output = '<a href="' . esc_url( $the_filter_url) .'" style="'.$shortcode_style.'">'.$content. '</a>';

 return  $output;

}

add_shortcode( 'language_wise_url', 'languageWiseUrl' ); // register shortcode