How to Add a Joomla Module Position Inside Any Component

Add a Joomla Module Position Inside Any Component

Do you know that you can display Joomla modules inside components? This is possible with only a single line of PHP code.

In this tutorial, I'm going to show you how to display a module inside any component.

We will use Joomla's com_articles component for this example. However, this approach works for any Joomla component.

Step #1. Create a template override

Let's create a template override to place our customizations safely.

  1. Go to Extensions
  2. Templates
  3. Templates (child menu)
  4. Your template details and files

Create a Joomla template override

We are about to create a template override for single articles.

  • Now go to the Create overrides tab.
  • In the "Components" column, click on com_content > article. A set of files will be generated in the folder /templates/your-template/html/com_content/article/

Create Joomla template override files

Step #2. Edit the template override

  • Go to the Editor tab
  • Find the file default.php inside the /com_content/article/ folder
  • Add the custom php code below where position-name means the name of your custom module position:
    <?php echo JHtml::_('content.prepare', ''); ?>

write the Joomla template override code

  • Click "Save & Close" when you're done

Step #3. Create a new module

Let's test our custom module position.

  • Go to Extensions > Modules > Add new.
  • Choose the module type you want. In our example, we're going use a Custom HTML module.
  • Type the new module position in the Position parameter, and press the Enter key. In this case, we're using position-name.
  • Under "Menu Assignment", make sure the module is enabled for all the pages.
  • Save and close the module.

Create a new Joomla module

Step #4. Check the end result

Preview one of your full articles in the frontend of your site. The module should be visible somewhere inside the article layout.


Have problems showing modules inside articles?

  • Go to Extensions > Plugins.
  • Make sure the plugin Content - Load modules is enabled.

Check your new Joomla module

About the author

Valentín creates beautiful designs from amongst the tequila plants of Jalisco, Mexico. You can see Valentín's design work all over this site and you can often find him helping members in support.