0

New Edit

I would like to show the_content BEFORE the more tag when the cookie is not set and the_content AFTER the more tag when the cookie is set.


I could not answer to my own question because my reputation is less than 10 so I will edit instead.

This is the final answer. This will show the_content before the more tag if the cookie is NOT set, and the_content AFTER the more tag once the cookie IS set. Very useful when creating Lead Gen landing pages or when you want to display some content before or after a certain action is taken.

Thanks.

<?php global $more;
while (have_posts()) : the_post();
if(isset($_COOKIE['CookieName'])) {
$more = 1;
the_content('',TRUE,''); } 
else {
$more = 0;
the_content(); } ?>
3
  • I think this is more of a jQuery/cookies/session question, rather than a WordPress-specific question. Can you please clarify the WordPress-specific nature of this question? Commented Nov 11, 2012 at 17:06
  • @ChipBennett Not sure about the close vote. Maybe this could be solved otherwise with WP.
    – kaiser
    Commented Nov 11, 2012 at 19:10
  • 2
    @kaiser as-written, the question isn't WP-specific. It's an if/then conditional based on a cookie. I'd be happy to recant a close vote if the question were edited to make it WP-specific. Commented Nov 11, 2012 at 19:20

1 Answer 1

0

Try using the jQuery Cookie plugin

You can set a cookie to start with that could be called InfoSubmitted with value of 'No' and when they submit their info it changes to 'Yes'

To set the cookie first make sure jQuery and the Cookie plugin are installed and then use this:

jQuery.cookie('InfoSubmitted', 'No');

Once the user submits the form then change the cookie to Yes:

jQuery.cookie('InfoSubmitted', 'Yes');

Once you have that working then you would need to check what value the cookie has.

if (jQuery.cookie('InfoSubmitted') == "No") {
    //do not show information

} else {
    //show information
}

This is all using jQuery and Javascript. You could possibly use PHP to read the cookies set by the plugin and use them in your PHP code

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.