-2

Background I use php CPT templates with ACF. Usually i get ACF variables and depending on these variables i use get_template_part() to display content. in other cases i just use echo to deliver content. So far, this is working out for years now.

Problem A customer is using DigiMember. DigiMember is a membership plugIn that uses shortcodes to protect/hide part of the content. This works only if the standard content output is used. so my get_template_part() sections interpret shortcodes as expected but my simple echo output sections do not and are not protected. i assume that digimember hooks itself in the main content function/loop in order to filter allowed content.

Shortcodes So far i successfully testet the do_shortcode() php function with the digimember shortcodes. anything within is protected. My idea was to collect all output in a variable with ob_start and then output this variable within the do_shortcode() function, but this seems a bit off?!?

My question Is there some kind of wrapper function in wordpress to output html/text instead of using simple echo? so that any string or ob_start buffer will be processed with all usual wordpress filters. ... or is my brain on a wrong path?

Thanks for your suggestions :)

  • Where is the content you are echoing coming/originating from ? – Jasper B Aug 20 '21 at 10:24
  • Alternatively you can also try using `_e()` this will run it trough the WordPress translator perhaps this is hooked by the plugin [source](https://developer.wordpress.org/reference/functions/_e/) – Jasper B Aug 20 '21 at 10:28
  • Yes! I tried this and its working. _e(), _x() are actually interpreting shordcodes and are hooked. Wonderful. +100 Karma for you. Thanks :) – Posi tron Aug 20 '21 at 13:54

1 Answers1

0

You could try doing something like:

$return = '<div>';
$return .= do_shortcode('[yourshortcode]');
$return .= '</div>';
echo $return;

or 

return $return // if your using the add_shortcode('short code function
MrJoshFisher
  • 1,143
  • 5
  • 21
  • 48
  • Exactly. Thats what i am doing now and its working so far. I was hoping for a wordpress function wp_output_content( $any_string ) function, appying all filters and shortcode interpretation like "the_content()" would do. Thanks – Posi tron Aug 20 '21 at 10:40