Magento WordPress Shortcodes & Widgets WordPress Code in Magento

« Back to Magento WordPress Shortcodes & Widgets

The Magento WordPress Integration module allows you to access all WordPress data through Magento blocks, models, collections and helpers, but sometimes you might want to use actual WordPress code in Magento. While it is recommended that you use the Magento equivalent code, if you really want to use WordPress code, you need to wrap it in a special piece of code.

Using WordPress Functions in Magento 1

<?php $coreHelper  = Mage::helper('wp_addon_pluginshortcodewidget/core') ?>
<?php $returnValue = $coreHelper->simulatedCallback(function() {
  // Any WordPress code can go here

  if ($post = get_post()) {
    return $post->ID;
  }

  return 0;
}); ?>

Using WordPress Functions in Magento 2

<?php // You should probably use DI ?>
<?php $om = \Magento\Framework\App\ObjectManager::getInstance() ?>
<?php $coreHelper  = $om->get('FishPig\WordPress_PluginShortcodeWidget\Helper\Core') ?>
<?php $returnValue = $coreHelper->simulatedCallback(function() {
  // Any WordPress code can go here

  if ($post = get_post()) {
    return $post->ID;
  }

  return 0;
}); ?>

Magento WordPress
Shortcodes & Widgets
Documentation

Post your comment

FishPig Ltd