我想在我的wordpress页面中为职业帖子添加一个动态JSON-LD(schema.org)。我在下面尝试了此代码。但我认为数组中有一些语法错误。可能是;“回声”;数组中不允许?我希望有人能帮我这个忙?
<?php function schema() {?>
<?php if( have_rows(\'schema_auszeichnung\') ): ?>
<?php while( have_rows(\'schema_auszeichnung\') ): the_row();
// Get sub field values.
$title = get_sub_field(\'title\');
$description = get_sub_field(\'description\');
$state = get_sub_field(\'state\');
$date = get_sub_field(\'date\');
$street = get_sub_field(\'street\');
$city = get_sub_field(\'city\');
$postalcode = get_sub_field(\'postalcode\');
$schema = array(
\'@context\' => \'http://schema.org\',
\'@type\' => \'JobPosting\',
\'title\' => $title,
\'description\' => $description,
\'hiringOrganization\' => array(
\'@type\' => \'Organization\',
\'name\' => \'cent GmbH\',
\'sameAs\' => get_home_url(),
\'logo\' => \'/wp/wp-content/uploads/2016/11/cropped-logo.png\'
),
\'employmentType\'=> $state,
\'datePosted\' => $date,
\'validThrough\' => "",
\'jobLocation\' => array(
\'@type\' => "Place",
\'address\' => array (
\'@type\' => \'PostalAddress\',
\'streetAddress\' => $street,
\'adressLocality\' => $city,
\'postalCode\' => $postalcode,
\'addressCountry\' => \'DE\'
),
),
);
?>
<?php endwhile; ?>
<?php endif; ?>
<?php
echo \'<script type="application/ld+json">\' . json_encode($schema) . \'</script>\';
}
add_action(\'wp_head\', \'schema\');
?>
编辑:
删除“echo”后,我得到了php警告:未定义变量:schema。但对我来说,它是在这行中定义的:$schema=array。。。。。