I’m writing a PHP WordPress plugin where I want to be able to call the functions I’ve defined in other parts of my website (e.g. on page templates).

I want to be able to pass arguments to my functions like so:

// Contained on Page Template to display content

$args1 = 'Hello';
$args2 = 'Goodbye';

saySomething( $args1, $args2);

// Contained within plugin file

function saySomething ($args1, $args2){

  //echo $args1 //Test Only
  //echo $args2 //Test Only

  function sayHello () {
      echo $args1;

  function sayGoodbye () {
    echo $args2;

I’ve already use ‘include_once’ to make sure I can call functions in my plugin file. However, for some reason the sub-functions (for want of a better word!) don’t seem to work. I’ve tried a few things, including redefining the arguments within the first function (e.g. $newargs = $args1). Any thoughts greatly appreciated.

Read more here: Pass an argument through one function to another function


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: