-1

Hi I am having trouble doing an if state in wordpress. If multisite network url equals then do something

Any help? Thanks

<?php
    var $china = "network_home_url()/china";
    if($china === true){?>
       <img src="..">
<?php } else { ?>
       <img src="..">
<?php } ?>
roshambo
  • 2,624
  • 6
  • 31
  • 54

2 Answers2

0

escape quotes, network_home_url() is php function:

var $china = network_home_url()."/china";

And for 'if' statement use not true but the url itself:

    if ($china == "http://somekindofurl.com/china") {
//do code
}
T.Ilciukas
  • 61
  • 5
0

This is not the ideal solution to compare with whole string.

Instead, you can use strpos() in PHP to check whether it contains 'china'

something like

$url = 'network_home_url()/china';

if (strpos($url, 'china') !== false) {

    echo '<img src="..">';
    /*this is true*/

} else {

   echo '<img src="..">';

}

Full doc strpos()

Thanks

Bilal Hussain
  • 994
  • 1
  • 10
  • 25
  • Hi thanks for your answer but I cannot get this working – roshambo Sep 26 '17 at 23:03
  • I answered with respect to your question. This may have errors but I ignored that. I just gave you an idea about the right way of to compare substring. Please post your complete code if you want complete working answer. Thanks – Bilal Hussain Sep 27 '17 at 09:03