admin管理员组文章数量:1130349
I'm trying to write reusable functions in a plugin and call the functions within a shortcode. But, I can't get any output. Why don't either of these methods work?
<?php
function say_sup(){
return 'sup';
}
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
$sup = say_sup();
return $sup;
}
?>
<?php
function say_sup(){
$sup = 'sup';
echo $sup;
var_dump( $sup );
}
add_action( 'say_sup_now', 'say_sup', 1 );
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
do_action( 'say_sup_now' );
}
?>
I'm trying to write reusable functions in a plugin and call the functions within a shortcode. But, I can't get any output. Why don't either of these methods work?
<?php
function say_sup(){
return 'sup';
}
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
$sup = say_sup();
return $sup;
}
?>
<?php
function say_sup(){
$sup = 'sup';
echo $sup;
var_dump( $sup );
}
add_action( 'say_sup_now', 'say_sup', 1 );
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
do_action( 'say_sup_now' );
}
?>
Share
Improve this question
edited Nov 4, 2018 at 11:55
James Valeii
asked Nov 1, 2018 at 14:50
James ValeiiJames Valeii
1185 bronze badges
3
|
1 Answer
Reset to default 0This is correct (I just had file versioning issues):
<?php
function say_sup(){
return 'sup';
}
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
$sup = say_sup();
return $sup;
}
?>
This is not correct - and there would be little purpose in trying to make something like this work, if the above worked:
<?php
function say_sup(){
$sup = 'sup';
echo $sup;
var_dump( $sup );
}
add_action( 'say_sup_now', 'say_sup', 1 );
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
do_action( 'say_sup_now' );
}
?>
I'm trying to write reusable functions in a plugin and call the functions within a shortcode. But, I can't get any output. Why don't either of these methods work?
<?php
function say_sup(){
return 'sup';
}
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
$sup = say_sup();
return $sup;
}
?>
<?php
function say_sup(){
$sup = 'sup';
echo $sup;
var_dump( $sup );
}
add_action( 'say_sup_now', 'say_sup', 1 );
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
do_action( 'say_sup_now' );
}
?>
I'm trying to write reusable functions in a plugin and call the functions within a shortcode. But, I can't get any output. Why don't either of these methods work?
<?php
function say_sup(){
return 'sup';
}
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
$sup = say_sup();
return $sup;
}
?>
<?php
function say_sup(){
$sup = 'sup';
echo $sup;
var_dump( $sup );
}
add_action( 'say_sup_now', 'say_sup', 1 );
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
do_action( 'say_sup_now' );
}
?>
Share
Improve this question
edited Nov 4, 2018 at 11:55
James Valeii
asked Nov 1, 2018 at 14:50
James ValeiiJames Valeii
1185 bronze badges
3
- Your first example is fine. Is this the actual code you’re having trouble with? – Jacob Peattie Commented Nov 1, 2018 at 15:19
-
I guess you forgot to write echo before do_shortcode(). It should be
echo do_shortcode('[your-shorcode]') ;– KAGG Design Commented Nov 1, 2018 at 17:16 -
@KAGGDesign They haven't written
do_shortcode()anywhere? – Jacob Peattie Commented Nov 2, 2018 at 1:09
1 Answer
Reset to default 0This is correct (I just had file versioning issues):
<?php
function say_sup(){
return 'sup';
}
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
$sup = say_sup();
return $sup;
}
?>
This is not correct - and there would be little purpose in trying to make something like this work, if the above worked:
<?php
function say_sup(){
$sup = 'sup';
echo $sup;
var_dump( $sup );
}
add_action( 'say_sup_now', 'say_sup', 1 );
add_shortcode( 'sup_shortcode', 'register_sup_shortcode' );
function register_sup_shortcode( $atts, $content = null) {
do_action( 'say_sup_now' );
}
?>
本文标签: pluginsReturn function results within shortcode
版权声明:本文标题:plugins - Return function results within shortcode 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749207215a2332767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


echo do_shortcode('[your-shorcode]') ;– KAGG Design Commented Nov 1, 2018 at 17:16do_shortcode()anywhere? – Jacob Peattie Commented Nov 2, 2018 at 1:09