php - Switch / Case to generate URL causes spaces -


i using switch case method generate correct image url websites icon.

  <div class="logo"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><img src="<?php bloginfo('stylesheet_directory'); ?>   <?php     $url = home_url( '/' );     switch ($url) {         case "http://dx.zachryracing.com/es/":             echo "/img/logo-spanish.png";             break;         case "http://dx.zachryracing.com/":             echo "/img/logo.png";             break;     }     ?>" alt=“zachry racing logo” /></a></div> 

my problem there 2 spaces being generated in url:

http://dx.zachryracing.com/es/wp-content/themes/boot_strap%20%20/img/logo.png

for example.

this simpler form working fine (without dynamism):

<div class="logo"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><img src="<?php bloginfo('stylesheet_directory'); ?>/img/logo.png" alt=“zachry racing logo” /></a></div> 

what doing wrong?

i think you're overcomplicating bit. try this

<img src="<?php bloginfo('stylesheet_directory'); $url = home_url( '/' ); echo (stripos($url, '/es/') !== false) ? "/img/logo-spanish.png" : "/img/logo.png"; ?>"> 

that should show spanish logo if url contains /es/ directory


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -