Magento 2 WordPress Integration Content Blocks Documentation
-
Installation
You can install the module for Magento 2 using Composer or you can manually install it using FTP.
ComposerManualRun the following commands in your Magento 2 root directory to install the module using Composer.
# Add the FishPig Composer repo composer config repositories.fishpig composer https://repo.fishpig.com/ # Install the module using Composer composer require fishpig/magento2-wordpress-integration-contentblocks:* # Enable the module in Magento 2 php bin/magento module:enable FishPig_WordPress_ContentBlocks # Run the Magento upgrade system php bin/magento setup:upgrade
You can download the latest version of the module by logging in to your account and selecting Account > Projects.
Extract the ZIP file and upload the files to your Magento site at the directory below:
app/code/FishPig/WordPress_ContentBlocks
When creating the folders, ensure you use the correct capitalisation.
To complete the installation, run the following commands in a terminal.
# Enable the module in Magento 2 bin/magento module:enable FishPig_WordPress_ContentBlocks # Run the Magento upgrade system bin/magento setup:upgrade
-
Add a Content Block
There are many ways to add content blocks from WordPress into your Magento website and all of them are easy.
Shortcodes
The easiest way to add a WordPress content block to your Magento website is to use the basic shortcode system that the module provides.
This allows you to specify a content block by it's ID or identifier (this is the slug/post_name/url_key from WordPress).
WordPress Content Block Shortcode by ID
The ID can be found in the URL while editing the content block in the WordPress Admin.
[wp_block id="1234"]
WordPress Content Block Shortcode by Identifier
In WordPress, the term 'slug' is used to determine the identifier for each content block and this works just like the url_key field in Magento. This can often be easier to remember than an ID.
[wp_block identifier="promo-listing-01"]
Widgets
The module adds a handy widget to Magento so you can include a content block from the Admin anywhere you would include a widget.
CMS Block Select/Dropdowns
Various places in the Admin, you will see a dropdown allowing you to select a CMS block to be automatically injected into your Magento site. This dropdown will now also include WordPress content blocks so you can easily select a content block from WordPress instead.
A great example of this is the category edit page as this allows you to select a CMS block for the category header. With Content Blocks installed, you can now generate your category header block from WordPress.
-
Ideas
The possibilities are endless with Content Blocks, but here's a few ideas to get you started.
Category Header
This ones easy. You can specify a content block using the CMS Block dropdown while editing a category. You can now design your category headers using Elementor and other WordPress plugins!
Product Description
Have you ever thought how cool it would be to build your product descriptions in WordPress? With Content Blocks, you can do this easily and create a dynamic system to do it.
First, start create a new content block and use the product SKU as the URL slug (identifier) in WordPress. Next, you can either manually add the following to your product description field, or better yet, create a template to dynamically output it to the page so that it's picked up and converted into the block.
[wp_block identifier="product-sku"]
If you don't have mnay products, you could manually add this to the description field in the Admin. If you do have lots of products, edit the description template to dynamically output this shortcode.
echo '[wp_block identifier="' . $block->escapeHtmlAttr($block->getProduct()->getSku()) . '"]';