How Do I Add a Product Schema in WordPress?

Adding a product schema in WordPress is a fairly simple process. After you have created your product archive, you will need to add the following line of code to your functions.php file:

function my_product_archive() { $schema = new WP_Product_Schema(); $schema->set_version(‘1.0′); $schema->set_name(‘My Product Archive’); $schema->set_description(‘A place to store all of your products’); $schema->set_author(‘Your Name’); $schema->set_publisher(‘Your Name’); $schema->set_category( ‘Product Category’); $schema->set_tax_class( ‘Tax Class’); $schema->set_tags(array(‘product’,’archive’,’my’,’product’,’schema’,’WordPress’)); return $schema; }

After you have added this line of code, you will need to create a new file called product.php and paste the following code into it:

Now you will need to create a new file called functions.php and paste the following code into it:

set_version(‘1.

0′); $schema->set_name(‘My Product Archive’); $schema->set_description(‘A place to store all of your products’); $schema->set_author(‘Your Name’); $schema->set_publisher(‘Your Name’); $schema->set_category( ‘Product Category’); $schema->set_tax_class( ‘Tax Class’); $schema->set_tags(array(‘product’,’archive’,’my’,’product’,’schema’,’WordPress’)); return $schema; } function add_to_cart() { $product = wp_get_object_by_ID(‘product’); $quantity = 1; $item_title = __(‘Product: ‘.$product->product_title); $item_price = $product->product_price; $total_price = $item_price + $quantity; $item = new WP_Item(); $item->set_item_title($item_title); $item->set_item_price($item_price); $item->set_item_tax_class($item_tax_class); $item->set_item_qty($item_qty); $item->set_item_description($item_description); $item->set_item_brand($item_brand); $item->set_item_stock($item_stock); $item->set_item_downloadable($item_downloadable); $item->set_item_description_long($item_description_long); $item->add_to_cart(); } add_action(‘admin_menu’, ‘add_to_cart’); ?>.

Now you will just need to add a link to your new product archive from within the admin area of your website. To do this, you will need to add the following line of code to your theme’s functions.php file:

function my_site_title() { return ‘My Site Title'; } add_action(‘admin_menu’, ‘my_site_title’);

Conclusion

function my_product_archive() { $schema = new WP_Product_Schema(); $schema->set_version(‘1.0′); $schema->set_name(‘My Product Archive’); $schema->set_description(‘A place to store all of your products’); $schema->set_author(‘Your Name’); $schema->set_publisher(‘Your Name’); $schema->set_category( ‘Product Category’); $schema->set_tax_class( ‘Tax Class’); $schema->set_tags(array(‘product’,’archive’,’my’,’product’,’schema’,’WordPress’)); return $schema; } function add_to_cart() { $product = wp_get_object_by_ID(‘product’); $quantity = 1; $item_title = __(‘Product: ‘.$product->product_title); $item_price = $product->product_price; $total_price = $item_price + $quantity; $item = new WP_Item(); $item->set_.