Function to function shortcode help

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I have been with this for several days to see if you can help me. I need to take the data of the variable $result, which is 6, from the operation function to my shortcode, how can I do this?

operation();

function operation(){
$result=5+1;
return $result;
}


function my_function($result){ //
return  $all=$result+5;
}
add_shortcode( 'my-shortcode', 'my_function' );

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I have been with this for several days to see if you can help me. I need to take the data of the variable $result, which is 6, from the operation function to my shortcode, how can I do this?

operation();

function operation(){
$result=5+1;
return $result;
}


function my_function($result){ //
return  $all=$result+5;
}
add_shortcode( 'my-shortcode', 'my_function' );

Share Improve this question edited Jul 5, 2020 at 8:17 Ivan Shatsky 8901 gold badge7 silver badges12 bronze badges asked Jul 5, 2020 at 0:38 StymarkStymark 372 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Not sure what you would need this for but this is how you take the data of the variable $result from the operation function to your shortcode:

operation();

function operation(){
$result=5+1;
return $result;
}

function my_function(){
$result = operation();
return (string)$result;
}
add_shortcode( 'my-shortcode', 'my_function' );

Do you mean something like this?

function some_function( $a ) {
    return $a * 2;
}
function my_shortcode( $atts ) {
    $params = shortcode_atts( array(
        'value' => 0
    ), $atts );
    return (string)some_function( $params['value'] );
}
add_shortcode( 'my-shortcode', 'my_shortcode' );

When you use [my-shortcode value=2] on your page, it would be substituted with the result of some_function(2) (i.e. 4).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742291658a4416303.html

相关推荐

  • Function to function shortcode help

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信