Wordpress 短代码 return 另一个 php 页面
Wordpress shortcode return another php page
当我 return 一些东西时,我的自定义 wordpress 插件短代码正在工作。但我想 return 另一个 php 页面,其中包括 html。
这是我的map.php
<?php
function example($map){
echo "Hello!";
}
?>
我试过这样
add_shortcode( 'map_shortcode', 'map_shortcode' );
function map_shortcode() {
wp_enqueue_style( 'my-css' );
wp_enqueue_style( 'meyer-reset' );
wp_enqueue_style( 'tooltipster-bundle' );
wp_enqueue_script( 'mypluginscript' );
return $map;}
?>
我的意思是简码有效;当我尝试像 'abc' 这样的简单字符串时,它显示了,所以它有效,但我想在 return 函数上显示其他页面。
要使用 WordPress 短代码显示 HTML 视图,您可以使用 ob_start()
和 ob_get_clean()
函数。
https://www.php.net/manual/en/function.ob-start.php
https://www.php.net/manual/en/function.ob-get-clean.php
<?php
function map_shortcode() {
ob_start();
?>
<!-- Your HTML codes here ... -->
<?php
return ob_get_clean();
}
add_shortcode("map_shortcode", "map_shortcode");
?>
当我 return 一些东西时,我的自定义 wordpress 插件短代码正在工作。但我想 return 另一个 php 页面,其中包括 html。
这是我的map.php
<?php
function example($map){
echo "Hello!";
}
?>
我试过这样
add_shortcode( 'map_shortcode', 'map_shortcode' );
function map_shortcode() {
wp_enqueue_style( 'my-css' );
wp_enqueue_style( 'meyer-reset' );
wp_enqueue_style( 'tooltipster-bundle' );
wp_enqueue_script( 'mypluginscript' );
return $map;}
?>
我的意思是简码有效;当我尝试像 'abc' 这样的简单字符串时,它显示了,所以它有效,但我想在 return 函数上显示其他页面。
要使用 WordPress 短代码显示 HTML 视图,您可以使用 ob_start()
和 ob_get_clean()
函数。
https://www.php.net/manual/en/function.ob-start.php
https://www.php.net/manual/en/function.ob-get-clean.php
<?php
function map_shortcode() {
ob_start();
?>
<!-- Your HTML codes here ... -->
<?php
return ob_get_clean();
}
add_shortcode("map_shortcode", "map_shortcode");
?>