1

My custom wordpress plugin shortcode is working when I just return something. But I want to return another php page, which includes html.

This is my map.php

<?php 
function example($map){
    echo "Hello!"; 
    }
?>


I've tried like this

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;}
?>

I mean the shortcode works; when I tried just a simple string like 'abc' it showed, so it works, but I want to show the other page on the return function.

1

1 Answer 1

5

To show an HTML view using WordPress shortcode, you can use ob_start() and ob_get_clean() functions.

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");
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.