I have a website that gets fed data from a local MLS. I put together PHP to grab the title of the page which contains the address & MLS # of the current property, and create schema for it. I also collect some information from meta and compase the image url based on known information. However, when I use the code below, my site becomes slow and starts to crash. I have put the script below just above the ending body tag, below wp_footer(). I would feel better about myself if the problem was something complex, but it is probably something dumb. Thank you in advance.
$path="http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];//gets url of current page
$tags = get_meta_tags($path); //retrieves an array of all meta name tags
$description= $tags['og:description']; // tag containing the property descriion
$the_address= explode(",",ucwords(strtolower(get_the_title())) ); //get post title, parse address parts
$street=$the_address[0];
$city =$the_address[1];
$add2 = explode ("(", $the_address[2]);
$state = strtoupper(substr($the_address[2],1,2));
$zip = substr($the_address[2],4,5);
$mls= substr($the_address[2],17,8); echo $mls;
$img_url = "/".substr($mls,5,3). "/f_". $mls. ".jpg";
$price="";
/*SCHEMA TYPE RESIDENCE */
$schema="<script type=\"application/ld+json\">{\"@context\": \"\",";
$schema.="\"@type\": \"Residence\",
\"name\":\"Home for sale in $city, $state\",";
$schema.="\"address\": {
\"@type\": \"PostalAddress\",
\"addressLocality\": \"$city\",
\"addressRegion\": \"$state\",
\"postalCode\": \"$zip\",
\"streetAddress\": \"$street\"
},
\"image\": \"$img_url\",
\"description\": \"$description\"
}";
$schema .= "</script>";
echo $schema;
/*SCHEMA TYPE PRODUCT */
$schema="<script type=\"application/ld+json\">{\"@context\": \"\",";
$schema.="\"@type\": \"Product\",
\"name\":\"Home for sale in $city, $state\",";
$schema.= "offers\":{
\"@type\":\"Offer\",
\"@context\":\"\",
\"price\":".$price.",
\"priceCurrency\":\"USD\",
\"availability\":\"\",
\"url\":\"".$path."\"},";
$schema.="\"name\": {" .$street;
"\"@type\": \"PostalAddress\",
\"addressLocality\": \"$city\",
\"addressRegion\": \"$state\",
\"postalCode\": \"$zip\",
\"streetAddress\": \"\"
},
\"image\": \"$img_url\",
\"description\": \"$description\"
}";
$schema .= "</script>";
echo $schema;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745631272a4637124.html
评论列表(0条)