Magento WordPress Shortcodes & Widgets DocumentationShortcodes & Widgets

« Back to Magento WordPress - Shortcodes & Widgets

Table of Contents
  1. Installation
  2. Shortcodes
  3. Product Shortcode
  4. WordPress Functions
Need Help?

info@fishpig.com

 
  • Installation

    You can install the module for Magento 2 using Composer or you can manually install it using FTP.

    • Run 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.co.uk/
          
      # Install the module using Composer
      composer require fishpig/magento2-wordpress-integration-pluginshortcodewidget:^3.0
      
      # Enable the module in Magento 2
      php bin/magento module:enable FishPig_WordPress_PluginShortcodeWidget
      
      # Run the Magento upgrade system
      php bin/magento setup:upgrade
    • You can download the latest version of the module from the Downloads page.

      Extract the ZIP file and upload the files to your Magento site at the directory below:

      app/code/FishPig/WordPress_PluginShortcodeWidget

      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
      php bin/magento module:enable FishPig_WordPress_PluginShortcodeWidget
      
      # Run the Magento upgrade system
      php bin/magento setup:upgrade

    ↑ Back to Top

  • Shortcodes

    Shortcodes can be rendered anywhere inside Magento and this is done via the \FishPig\WordPress\Block\Shortcode class.

    Shortcodes in .phtml Files

    If the .phtml file is loaded using a block that extends from \FishPig\WordPress\Block\AbstractBlock, you can make use of the renderShortcode method:

    echo $block->renderShortcode('[gravityforms id="1"]');

    If the above doesn't work, you are using a Block that does not inherit from \FishPig\WordPress\Block\AbstractBlock. In this case, you will need to create a Shortcode block.

    echo $block->getLayout()
        ->createBlock(\FishPig\WordPress\Block\Shortcode::class)
        ->setShortcode('[ninja_form id=1]')
        ->toHtml();

    Using a Shortcode in a Magento 2 WYSIWYG Editor

    If you're adding content to a WYSIWYG editor, you won't be able to use PHP. Instead, you can use the pre-made block to add shortcodes. {{block class="FishPig\WordPress\Block\Shortcode" shortcode="[contactform7 id=\"123\"]"}}

    One important thing to note is that any " in the shortcode must be escaped using a slash (eg. \") so id="123" becomes id=\"123\"

    ↑ Back to Top

  • Product Shortcode

    The Shortcodes & Widgets add-on module allows you to use a Product shortcode to quickly and easily add product lists directly into your WordPress posts and pages.

    Product Shortcode Options

    There are several options for the product shortcode and these can be used separately or combined.

    ids

    A comma separated list of product IDs. Products will be ordered using the order you enter the IDs.

    [product ids="123,54,76,124"]

    skus

    A comma separated list of product SKUs. Products will be ordered using the order you enter the SKUs.

    [product skus="first-sku,second-sku,another-product"]

    category_id

    A single category ID. Products will be ordered using the position in the category.

    [product category_id="3"]

    on_sale

    A 1 to include products on sale and a 0 to include products not on sale

    [product on_sale="1"]

    limit

    Entering 0 removes the limit. Any other number will limit products to this number. This must be used in conjunction with another option.

    [product on_sale="1" limit="12"]

    Combining Options

    You can combine options above into a single Product Shortcode.

    This shortcode will display 12 products that are on sale from the category with the ID or 3.

    [product category_id="3" on_sale="1" limit="12"]

    ↑ Back to Top

  • WordPress Functions

    From version 3.0, the module now uses the WordPress API rather than direct code access. As a result it's now possible to integrate WordPress on different servers. It is no longer possible to run WordPress code in Magento. Any such code will need to be refactored into Magento code, which will be more secure. If you need help with this then please get in touch.

    ↑ Back to Top

Here's some of our new releases...

These new modules are for Magento 2 WordPress Integration.