最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Function to function shortcode help

programmeradmin3浏览0评论
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).

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论