$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>filters - How to take shortcode and content separately from a page?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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] ); ?>

Post a comment

comment list (0)

  1. No comments so far