Log In Prompt in the Middle of Posts
Shows a small "Log in or create an account" box halfway through articles for visitors who are not logged in.
Opens WPIDE on
Code
<?php if ( ! is_user_logged_in() ) : ?>
<aside class="wpide-login-prompt" style="margin:2em 0;padding:1em 1.25em;border-left:4px solid currentColor;background:rgba(127,127,127,.08)">
<p style="margin:0">
<strong>Join the conversation.</strong>
<a href="<?php echo esc_url( wp_login_url( get_permalink() ) ); ?>">Log in</a>
<?php if ( get_option( 'users_can_register' ) ) : ?>
or <a href="<?php echo esc_url( wp_registration_url() ); ?>">create a free account</a>
<?php endif; ?>
to comment and get updates.
</p>
</aside>
<?php endif; ?>
Notes
The "create an account" link only appears when "Anyone can register" is enabled.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.