How to add custom scheme for rach blog post wordpress
- User
How to add custom scheme for rach blog post wordpress
- Assistant
How to add custom scheme for rach blog post wordpress
Adding a custom schema (structured data) to each blog post can help enhance your site's visibility in search engine results by providing search engines with more detailed information about your content. Here’s a step-by-step guide on how to add a custom schema to each blog post in WordPress:
The easiest way to add schema to your blog posts is by using a dedicated plugin. There are several plugins available for this purpose:
All in One Schema Rich Snippets:
Schema Pro (Premium):
If you prefer to add schema manually, you can insert JSON-LD (JavaScript Object Notation for Linked Data) directly into your blog posts. Here’s how to do it:
Create Your Schema Markup:
Insert the Schema Markup into Your Blog Post:
Edit your blog post in WordPress.
Switch to the Text/HTML editor.
Paste the JSON-LD code within a <script> tag before the closing </body> tag or in the head section of your post. Here’s an example template:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "Your Blog Post Title",
"image": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
],
"datePublished": "2023-10-09T09:00:00+08:00",
"dateModified": "2023-10-09T09:20:00+08:00",
"author": {
"@type": "Person",
"name": "Author Name"
},
"publisher": {
"@type": "Organization",
"name": "Publisher Name",
"logo": {
"@type": "ImageObject",
"url": "https://example.com/logo.jpg"
}
},
"description": "A short description of your blog post."
}
</script>
Make sure to replace the placeholders with actual data from your blog post.
Save and Publish:
For more advanced users, you can add schema to your theme’s functions.php file to apply schema dynamically to every post:
Edit functions.php:
functions.php of your active theme.Add the Following Code:
function add_blog_post_schema() {
if (is_single()) { // Only on single posts
global $post;
$schema = array(
'@context' => "https://schema.org",
'@type' => "BlogPosting",
'headline' => get_the_title(),
'image' => wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full')[0],
'datePublished' => get_the_date('c'),
'dateModified' => get_the_modified_date('c'),
'author' => array(
'@type' => 'Person',
'name' => get_the_author()
),
'publisher' => array(
'@type' => 'Organization',
'name' => get_bloginfo('name'),
'logo' => array(
'@type' => 'ImageObject',
'url' => get_theme_mod('custom_logo') ? wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'full')[0] : ''
)
),
'description' => get_the_excerpt()
);
echo '<script type="application/ld+json">' . json_encode($schema) . '</script>';
}
}
add_action('wp_head', 'add_blog_post_schema');
Save Your Changes:
functions.php file.By following one of these methods, you can add custom schema markup to each blog post, enhancing your SEO and providing search engines with more detailed information about your content.
Not yet included in a published release.