Add a Custom Text Field to a Joomla Template

How to Add a Custom Text Field to a Joomla Template

Do you need to add a new setting in your Joomla template? With a few lines of PHP and XML code you can add a text field to print custom text in your public site.

In this post, I'm going to share with you how to add a custom text field to a Joomla 3 template.

Before to start, be sure you're using a template that doesn't expect updates from the developer in future. If necessary, work the customizations in a duplicated one.

Step #1. Access Template Editor

  1. Go to Extensions
  2. Templates
  3. Templates (on the left side)
Add Custom Param to a Joomla Template
  • Your Template Details and Files
Add Custom Param to a Joomla Template

Step #2. Edit templateDetails.xml file

  • Click templateDetails.xml
  • Edit the code in the right side of the screen
Add Custom Param to a Joomla Template

To add a simple text field, use the code below inside the <fieldset> tag:

<field name="customfield"  type="text" default=""
    label="Custom Field Label"
    description="Custom Field Alt Label"
    filter="string" />

  • Set a unique name value. In my example I use "customfield”.
  • Type a clear label and description.
  • Default is optional. Set a default value when the field is saved empty in step 4.
  • Filter is optional. In this case, it prevents to save html tags.
Add Custom Param to a Joomla Template
  • Save changes when you're done.

Step #3. Edit index.php file

I want to display my custom field next to "© 2015 Joomla!!" text in the footer:

Add Custom Param to a Joomla Template

Let's find that place in the template to print the value from our new field.

  • Click index.php
  • Edit the code in the right side
Add Custom Param to a Joomla Template

Look for the right place in index.php file, and type some PHP code:

<?php echo $this->params->get('customfield'); ?>

Replace 'customfield' with the name of your custom field from step 2.

Add Custom Param to a Joomla Template
  • Save and close.

Step #4. Test the new field

  • Go to Extensions > Templates > Styles > Your template style
  • Look for the new param and type some text
  • Save when you're done
Add Custom Param to a Joomla Template

Step #5.  End result

Go to your public site and see the new field in action:

Add Custom Param to a Joomla Template