-2
$teste_tp_slugs = ['company', 'search', 'customers'];
foreach ($teste_tp_slugs as $teste_tp_slug) {
$output = '';
$output .= '<section id="teste-site-home-' . $teste_tp_slug . '">';
$output .= '<div class="container">';
$output .= '<div class="row">';
$output .= get_template_part('template-parts/home/sections/content', 'company');
$output .= '</div>';
$output .= '</div>';
$output .= '</section>';
return $output;
}
You’re showing off like this, off the ROW
The right thing would be
This is usage error, you are using a syntax that does not correspond to manual orientation. This function does not return the value to concatenate, it plays the part in the output. What happens there is that you are generating the part immediately in the HTML, and then print the output (after you have already played the part in the output) then it is expected that the result of the function will come first. Show the output until you open the dív, then you call the function, and then close the div and the rest, then it is in the desired sequence.
– Bacco
@Johnnysilva note that this is a feature of the wordpress function you are using. It doesn’t return the value in the function, it plays straight out, so you can’t concatenate. I could understand what you want, but the function was not made to use like this (I think it would be better if it worked as you imagined, but whoever did the WP does not think the same way). You could do an exit with output buffer, but I think it gets worse. (starts with
ob_start();
, gives echo and at the end makes$output = ob_get_contents()
;– Bacco
@Bacco understand, really has to be using "echo". I appreciate it, I’m still learning, and I need some of the information, but somehow I found the information.
– Johnny Silva
@Johnnysilva I pressed the answer below the colleague Heathcliff to clarify better, test and see if solved. The "output buffer" avoids direct output in HTML, and at the end it plays in the value Return.
– Bacco
@Bacco Thank you very much!
– Johnny Silva
@Johnnysilva note that if you give a Return inside the foreach will only see the first Slug, need to do the Return off, I hit this in the code of the fellow tb
– Bacco
@If you use "echo" you don’t even need ob_start() and Return at the end, it already displays all rsrs.
– Johnny Silva
Yeah, it gets simpler, so I initially suggested echo. The output buffer solution is only interesting if you then need to concatenate the result with something else. In general, the less complicated, the better. I sincerely avoid using output buffer whenever possible The rare cases it makes sense to use are just these, of using something ready from third parties that does not work as expected (it almost always pays to do right and dispense with third-party code, in particular wordpress, which "redoes" something that PHP already has much simpler native)
– Bacco