filters - How to take shortcode and content separately from a page?

admin2025-06-03  4

I have a page with content and shortcode for the contact form. I want to display the content of the page in one div and the shortcode in another div(that means the form should render in another div). How to implement this? I tried
<?php remove_filter( 'the_content', 'do_shortcode', 11 ); the_content(); add_filter( 'the_content', 'do_shortcode', 11 );*/ ?>

for filtering the content only...but it displays the shortcode as it is.([contact-form-7 id="72" title="Contact form 1" html_class="col-lg-8 col-md-8 col-sm-12 col-12 dose-contact-form row"]).How to ffx this?

I have a page with content and shortcode for the contact form. I want to display the content of the page in one div and the shortcode in another div(that means the form should render in another div). How to implement this? I tried
<?php remove_filter( 'the_content', 'do_shortcode', 11 ); the_content(); add_filter( 'the_content', 'do_shortcode', 11 );*/ ?>

for filtering the content only...but it displays the shortcode as it is.([contact-form-7 id="72" title="Contact form 1" html_class="col-lg-8 col-md-8 col-sm-12 col-12 dose-contact-form row"]).How to ffx this?

Share Improve this question edited Feb 15, 2019 at 5:10 beginner asked Feb 15, 2019 at 5:05 beginnerbeginner 1672 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found the solution. I used the following codes and it worked for me . To remove the shortcode from the content, I Used this <?php $content = get_the_content(); $content = preg_replace("/\[.*]/m", " ", $content);
$content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; ?>

and the following code to get the shortcode only from post content <?php $pattern = get_shortcode_regex(); $matches = array(); preg_match_all("/$pattern/s", get_the_content(), $matches);
echo preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $matches[0][0] ); ?>

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748905151a314694.html

最新回复(0)