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 badges1 Answer
Reset to default 0I 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] );
?>