the page automatically display a number inside a div called wpb_wrapper, when I use a custom shortcode. but its nowhere in my function. When I delete the shortcode the number goes away.
<div class="wpb_text_column wpb_content_element " >
<div class="wpb_wrapper">
1
</div>
</div>
Any clues?
Is a custom Shortcode to display a grid of post, it contains PHP code, HTML tags and CSS.
function millennium_grid(){
return include("mg-custom-grid.php");
add_shortcode('millennium', 'millennium_grid');
the page automatically display a number inside a div called wpb_wrapper, when I use a custom shortcode. but its nowhere in my function. When I delete the shortcode the number goes away.
<div class="wpb_text_column wpb_content_element " >
<div class="wpb_wrapper">
1
</div>
</div>
Any clues?
Is a custom Shortcode to display a grid of post, it contains PHP code, HTML tags and CSS.
function millennium_grid(){
return include("mg-custom-grid.php");
add_shortcode('millennium', 'millennium_grid');
Share
Improve this question
edited Nov 21, 2018 at 15:28
Trauko
asked Nov 21, 2018 at 15:17
TraukoTrauko
251 silver badge6 bronze badges
1
- 1 Which shortcode / plugin you are referring to? Can you be more specific? – middlelady Commented Nov 21, 2018 at 15:23
1 Answer
Reset to default 1You can't return
an include
like that. A successful include()
itself returns 1
, and since you're returning the return value of include
, your shortcode is displaying "1".
Handling Returns: include returns FALSE on failure and raises a warning. Successful includes, unless overridden by the included file, return 1.
— http://php/manual/en/function.include.php
If you want to output a template or similar file from shortcode, you need to capture it with output buffering:
function millennium_grid() {
ob_start();
include 'mg-custom-grid.php';
return ob_get_clean();
}
add_shortcode( 'millennium', 'millennium_grid' );