1

I have content locker plugin.

For locking contents, im using this shortcode:

[wp-like-locker] Your locked content here... [/wp-like-locker]

and I need lock every post on my blog. How could I instert this shortcodes into theme and lock:

Thank you very very very much for your answer and time!

3 Answers 3

2

You can hardcode shortcodes into a theme using do_shortcode. http://codex.wordpress.org/Function_Reference/do_shortcode

echo do_shortcode('[wp-like-locker] Your locked content here... [/wp-like-locker]');

You will most likely want to replace the hard-coded "Your locked content here..." with the function that pulls the content from the editor, like the_content http://codex.wordpress.org/Function_Reference/the_content

It might look like

  // the loop
  $content = get_the_content();
  echo do_shortcode('[wp-like-locker]' . $content .  '[/wp-like-locker]');
1
  • ...or just call the function attached to that shortcode directly and pass $content to it; no need for the extra overhead of do_shortcode... May 8, 2012 at 21:13
1

It would be both faster and cleaner to write a function to do this and put it in functions.php. It'd look like this (untested):

add_action( 'the_content', 'wpse49094_lock_content' );
function wpse49094_lock_content( $content ) {
    if( in_the_loop() ) {
        $content = do_shortcode( 'do_shortcode('[wp-like-locker]' . $content .  '[/wp-like-locker]');
        return $content;
    }
}
0

you can use do_shortcode() evaluate your short code.

you can place below code into sigle.php in your wordpress theme. And this will apply all of your posts those are using default template.

   <?php 
    get_template_part( 'content', 'single' ); 

echo do_shortcode('[wp-like-locker]');

echo "Your locked content";

echo do_shortcode('[/wp-like-locker]');

?>
1
  • 1
    This code is wrong. Check out the do_shortcode() Codex page to see how to handle open-close shortcodes.
    – mrwweb
    May 8, 2012 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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