1

In my theme function.php i am trying to add shortcodes for myHeader, myFooter etc .

Inside myHeader(), myFooter() function i added another function like fn_1(), fn_2(), fn3_() etc these function would be change weekly or monthly basis.

Is it possible to call a shortcode as written below

function myHeader(){
    fn_1();
    //fn_2();
}

function myFooter(){
    fn_2();
//  fn_3();

}
add_shortcode('myFooter', 'myHeader');
add_shortcode('myFooter', 'myFooter');


function fn_1(){
    return 'something for 1';
}

function fn_2(){
    return 'something for 2';
}

function fn_3(){
    return 'something for 3';
}

In my post i call my shortcode as [myHeader] and [myFooter]

2 Answers 2

3

It is possible, you just need to return something inside your shortcode methods. Shortcode functions also require some variables, though they don't actually have to be used.

eg.

function myHeader($atts, $content = null){
   $temp = fn_1();
   return $temp;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply, it is compulsory to add the parameter ($atts, $content = null), because I am not passing any parameters to myHeader(), myFooter function, it just return some string
From my experience, it's better to add the parameters.
thanks will try it, and if this work will mark as an answer
0

$atts is required to create shortcode if you are passing $atts or not.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.