0

I use Microdata attributes in HTML code.

How can I add Microdata attributes to the following tag (PHP)?

if (!empty($speciality)) {
echo "<p><strong>" . __('Speciality', 'framework') . "</strong><span>" . $speciality . "</span></p>";}

The page will not load when I enter the following way :

echo "<p itemscope itemtype="https://schema.org/medicalSpecialty"><strong>" . __('Speciality', 'framework') . "</strong><span itemprop="medicalSpecialty" >" . $speciality . "</span></p>";
1
  • Notice your mistake here: "<p itemscope itemtype="https:.. you have two ", one should be escaped or ' must be used. I also don't understand what this here should do: __('Speciality', 'framework'). Could you explain it to me? Commented Aug 12, 2017 at 10:48

2 Answers 2

1

you are using double quotes in a double quotes which is wrong, use backslash or single quote when you need. Try This code

echo "<p itemscope itemtype='https://schema.org/medicalSpecialty'><strong>" . __('Speciality', 'framework') . "</strong><span itemprop='medicalSpecialty' >" . $speciality . "</span></p>";
Sign up to request clarification or add additional context in comments.

Comments

0

You're mixing single and double quotes but you need to reserve either single or double quotes to escape the string so that your PHP isn't read as HTML when echoed. The below snippet will work without any errors:

if (!empty($speciality)) {    
echo "<p itemscope itemtype='https://schema.org/medicalSpecialty'><strong>'". 
__('Speciality', 'framework') . "'</strong><span itemprop='medicalSpecialty' 
>'" . $speciality . "'</span></p>";
}

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.