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 questionI 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 questionI 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
2 Answers
Reset to default 1Not 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
).