Orange Collar Media
Orange Collar Media
DOCS
ORANGECOLLAR/MODULE-WORDPRESS-INTEGRATION · EXTENDING THE MODULE

Extend WordPress Integration with template overrides, plugins, preferences, and custom widgets

  • Magento
  • Adobe Commerce
  • Hyvä

Template Overrides

Override any template in your theme at the matching path:

DIRECTORY TREE
app/design/frontend/Vendor/Theme/
  OrangeCollar_WordPressIntegration/
    templates/
      blog/post/view.phtml
      blog/index.phtml
      sidebar/categories.phtml
      ...

Layout XML Overrides

Create layout files in your theme matching the blog layout handles:

DIRECTORY TREE
app/design/frontend/Vendor/Theme/
  OrangeCollar_WordPressIntegration/
    layout/
      orangecollar_blog_index.xml
      orangecollar_post_view.xml

Custom API Client Plugin

To intercept or modify API calls, create a plugin on ClientInterface:

PHP
class MyClientPlugin
{
    public function afterGetPosts(
        ClientInterface $subject,
        array $result,
        array $params = []
    ): array {
        // Modify or log the result
        return $result;
    }
}

Register it in your module’s etc/di.xml:

XML
<type name="OrangeCollar\WordPressIntegration\Model\Api\ClientInterface">
    <plugin name="my_client_plugin" type="My\Module\Plugin\ClientPlugin" />
</type>

Custom Preference

To replace the API client entirely with your own implementation:

XML
<preference for="OrangeCollar\WordPressIntegration\Model\Api\ClientInterface"
            type="My\Module\Model\Api\CustomClient" />

Your class must implement all 18 methods in ClientInterface.

Custom Sidebar Block

Create a new block class extending the base:

PHP
class MyCustomSidebarBlock extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        private readonly PostRepositoryInterface $postRepository,
        Template\Context $context,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }

    public function getFeaturedPosts(): array
    {
        return $this->postRepository->getByCategory('featured', 1);
    }
}

Add it to any blog layout handle via layout XML.

Custom Widget Type

Declare a new widget in etc/widget.xml:

XML
<widget id="my_custom_wp_widget"
        class="My\Module\Block\Widget\Custom"
        is_email_compatible="false">
    <label translate="true">My Custom WordPress Widget</label>
    <description translate="true">Displays custom WordPress content</description>
    <parameters>
        <parameter name="count" xsi:type="text" visible="true" required="false" sort_order="10">
            <label translate="true">Item Count</label>
            <value>5</value>
        </parameter>
    </parameters>
</widget>

Adding a New Blog Page Type

To add a new URL pattern (e.g., /blog/series/{slug}):

  1. Create a controller class in Controller/Series/View.php
  2. Add the route pattern to Router::resolveRoute() using a plugin or preference
  3. Create a layout handle file: view/frontend/layout/orangecollar_series_view.xml
  4. Create the template