How to create shortcodes with function inside function in wordpress

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.

Read More

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]

Related posts

2 comments

  1. 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;
    }
    

Comments are closed.