kcr*_*kcr 1 html php wordpress plugins shortcode
当我返回一些东西时,我的自定义 WordPress 插件短代码就可以工作。但我想返回另一个 php 页面,其中包含 html。
这是我的map.php
<?php
function example($map){
echo "Hello!";
}
?>
Run Code Online (Sandbox Code Playgroud)
我试过这样
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;}
?>
Run Code Online (Sandbox Code Playgroud)
我的意思是短代码有效;当我尝试只显示一个简单的字符串(如“abc”)时,它显示了,所以它有效,但我想在返回函数上显示其他页面。
要使用 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");
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2180 次 |
| 最近记录: |