Jump to content

Archived

This topic is now archived and is closed to further replies.

jane

Hiding Scroll Spy on password protected pages

Recommended Posts

jane

I have scroll spy on this password protected page:

 

 

As you can see, the scrollspy is visible (since it's not in the wp-content loop). I would like it to also be hidden from view until the reader enters in a password.

 

I've researched this issue and found this post which looks like it provides a solution http://wordpress.org/support/topic/hide-sidebar-content-if-page-is-password-protected

 

I've modified the code and would like to know if the modification is correct. If it is, I was also wondering if I could add a PL Next box above my scroll spy and add the code in to make it work?

 

Any advice would be great.

 

Thanks.

 

<div id="spynav">
<?php
global $wp_query;
$postid = $wp_query->post->ID;
if ( !post_password_required() ) {
echo get_post_meta($postid, 'progress', true);}
wp_reset_query();
?>
    <?php if ( !function_exists('spynav') || !spynav("spynav") ) : ?>

    <?php endif; ?>
</div>

Share this post


Link to post
Share on other sites
Danny

Hi,

 

I don't think you're going to be able to add that snippet as you can't insert that code as there is no template code to edit and I don't think there is a hook to target where you need to insert the code.

For me the simplest method is to use a plugin such as S2Member, this adds restrictions on the actual page and not the content only. You can edit these restrictions on a page by page basis to.

 

I will bring this idea of yours to Simon and see if we can get it added to the DMS Pro Tools Allow Hidden Sections option.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
jane

Ah ok, thanks for the explanation. I wasn't sure it it would be possible but thought it was at least worth asking.

 

For now I'll just delete the scroll spy; that would be great if you can put the idea forward.

Share this post


Link to post
Share on other sites
Simon

Simples

 

https://gist.github.com/Pross/4dbf4b2ee8b74ccc47ac

 

Then use .password-required class to hide scrollspy.

Share this post


Link to post
Share on other sites
jane

Ah, OK - thank you for that Simon_P! I did try added it to my child theme's functions.php and it did something rather strange to the layout (stretched everything out so that the page "borders" where right at the edge of the screen). Is that indeed, where I should be adding this code or do I add it somewhere else?

Share this post


Link to post
Share on other sites

×