Wordpress短代码返回另一个php页面

问题描述 投票:1回答:1

当我返回一些东西时,我的自定义wordpress插件短代码正在工作。但我想返回另一个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'时,它显示,所以它工作,但我想在返回函数上显示另一页。

php html wordpress plugins shortcode
1个回答
1
投票

要使用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");
?>
© www.soinside.com 2019 - 2024. All rights reserved.