InMotion Hosting Support Center

Joomla 2.5 has reached its end of life as for 12/31/2014. Please be advised this may be a security risk to your website. You can view more information about the end of life here.

In our last few tutorials, we have been creating our own Joomla 2.5 plugin. The plugin is a simple Hello World plugin that prints Hello World before each article. We're going to make this plugin even better by allowing the user to specify custom text. If the user doesn't want to display "Hello World", they can display anything else they want, such as "Howdy Internet!"

In this Joomla 2.5 plugin tutorial, we're going to show you how to add a simple parameter to your plugin. Our parameter is going to be called "Alternative Text", and will allow the user to type in another message besides Hello World.


Step 1: Add the new parameter to your XML file

New parameters in Joomla 2.5 plugins are contained within fields and fieldsets, which are added to the plugin's xml file. We'll show you the basic code for adding a new parameter below, and in another tutorial we'll go into further details about how it works.

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="content">
        <name>Hello World</name>
        <author>Brad Markle</author>
        <creationDate>June 18th, 2012</creationDate>
        <copyright>InMotion Hosting</copyright>
        <license>GNU General Public License</license>
        <description>This is my very first plugin! Simple Hello World Plugin that prints "Hello World" at the beginning of every article.</description>
                <filename plugin="helloworld">helloworld.php</filename>
                <fields name="params">
                        <fieldset name="basic">
                                <field name="alt-text"  type="text" default="" label="Alternative Text" description="Besides Hello World, you can specify other text here to print to the screen instead." />


Step 2: Add a value to the parameter

alt-text-showing-in-plugin-settingsNow that that we have updated our xml file with a new attribute, we will give this attribute a new value. To do this, go to your Joomla 2.5 plugin manager and save a new value. Refer to the screenshot to the right to see where we entered our Alternative Text Howdy Internet!


Step 3: Accessing the Plugin Parameter from PHP

Now that we've saved our new plugin parameter, we can use it in our code! Accessing a plugin parameter can be done using the following code:


The following is our updated php code in helloworld.php:


// no direct access
defined('_JEXEC') or die;

class plgContentHelloworld extends JPlugin
        public function onContentAfterTitle($context, &$article, &$params, $limitstart)
                // If the user has entered alternative text to use
                // besides "Hello World", then return that instead.
                        return $this->params->get('alt-text');
                        return "<p>Hello World!</p>";


As you can see in the screenshot below, as we saved alternative text, it now shows instead of the standard Hello World text.

Continued Education in Course 215: Joomla 2.5 Content Plugin Development
You are viewing Section 4: How to add a parameter to a Joomla 2.5 plugin
Section 3: How to change a Joomla 2.5 plugin installation description
Section 5: Understanding Joomla 2.5 plugin parameter fields
n/a Points
2014-12-10 3:44 pm

thanx for this article - solved my problem

n/a Points
2014-12-10 3:45 pm
thanx for this article
n/a Points
2015-04-06 7:06 pm

What do you do if the plugin parameters are not displaying?

36,928 Points
2015-04-07 7:40 am
Hello Walt,

At that point, the standard coding torubleshooting techniques would apply.

Kindest Regards,
Scott M
n/a Points
2015-04-07 10:23 am

Scott,I figured out the issue I was seeing (or rather not seeing).  At the point <fieldset name="basic"> I had made a syntax mistake and had a name for the fieldset that included a space like this <fieldset name="Additional Fields">. Rather than an underscore like this <fieldset name="additional_fields">.Once I switched to underscores I was able to see my fields. 

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

8 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!