customization - Create Schema in WordPress with PHP

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 t

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

相关推荐

  • customization - Create Schema in WordPress with PHP

    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 t

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信