Hi folks hope you are doing good, this is a quick tutorial. In this tutorial, I will explain how to create WordPress page content for member only.
If you want to make some content of your page or post is private and only available for website member only, then keep your close attention in this post. In this tutorial, I will create a short code to protect your content from a non-member of your website.
Open functions.php file from your current activated theme folder and copy paste below code at the end of the file. Below shortcode allows you to share the private content in your page or post for your website member only.
It will appear login form for the non-member user. This will also boost signup on your website.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function membersOnly( $atts, $content = null ) { if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) { return $content; return ''; } else { $yonlendir = get_permalink(); $form = wp_login_form(array('echo' => false, 'redirect' => $yonlendir )); return $form; } } //shotcode to use into page/post add_shortcode( 'mem', 'membersOnly' ); |
Now you can use the [mem] ..your content.. [/mem]
into your pages/posts to write content private, only for member only.
If you enjoy this tutorial, do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: wordpress functions, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials, wordpress tutorials for beginners, wordpress tutorils