0

Is there any way to use shortcode to block the display of the post content?

What I want is to use the shortcode to pull the post content directly from the database, manipulate it, and then display it with the shortcode.

But if I do this, the post content displays twice. Once as it prints normally and again when the shortcode displays it.

Is there any way to use shortcode to stop the_content() from executing?

  • How do you create your shortcode? – Jevuska Mar 23 '16 at 12:57
  • Where is your shortcode code and what is the context for which you are showing this content? single.php, page.php etc... or something else? – userabuser Mar 23 '16 at 12:58
  • The shortcode is in a single post. The shortcode itself is being registered by a custom plugin. – ibhhvc Mar 23 '16 at 13:18
0

Instead of use of shortcode, you can get the post content, format them the way you want and display them later.

You can use get_the_content function; which will just retrieve post content in a variable.

    $raw_input = get_the_content();
/*process your content here and store the result in variable
eg.*/ 
$raw_input = str_replace("No", "Yes", $raw_input);
print $raw_input;

This will print the processed content and you can just comment out the_content() function in your single.php.

  • Just curious but could you do this in a way so you wouldn't have to edit the theme files? – yobddigi Mar 24 '16 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.