0

I am new to PHP and WordPress and currently in learning phase.I am trying to append the host name of in my WordPress site URL so that i can change the host name at any time and here is waht i am trying to do

<?php
   $site="siteurl";
   $home="home";
?>

this is what i am trying to do in my php page

<link rel="stylesheet" href ="<?php echo get_cdn($site_cdn); ?>/wp-
content/themes/abc/scripts/fancybox/jquery.fancybox-1.3.4.css" 
type="text/css" />

here is my get_cdn() function

function get_cdn($cdn_name){
 if ($cdn_name="home" || $cdn_name="siteurl"){
     return "http://id.cloudfront.net";
  }
  else{
     return $cdn_name;
  }
}

so what i am trying to do is if the pass in value to the function is either home or siteurl, it will return the URL of amazon cdn server so as per my understanding the above script should be like

<link rel="stylesheet" href ="http://id.cloudfront.net/wp-
    content/themes/abc/scripts/fancybox/jquery.fancybox-1.3.4.css" 
    type="text/css" />

but this is coming as

http://localhost/wordpress/id.cloudfront.net/wp-content/themes/abc/scripts/fancybox/jquery.fancybox-1.3.4.css

i am not sure why this is happening and any help/pointer in this regard will be helpful

2 Answers 2

4

if($cdn_name == "home" || $cdn_name == "siteurl"){

To match two values with eachother, use $a == $b. Two "=" that is. In PHP, === will also match the datatype.

Sign up to request clarification or add additional context in comments.

Comments

1

what is $site_cdn parameter you are sending, check that first.

It looks like you are sending an empty parameter, so your get_cdn function returns an empty string, and your src attribute is like

src="/wp-content/themes/abc/scripts/fancybox/jquery.fancybox-1.3.4.css"

and since you didn't specify any host, html fetches the css from your localhost

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.