Facebook Pixel

How to turn WordPress into an intranet? Two different approaches

How to turn WordPress into an intranet? Two different approaches
Do you want to manage a set of resources for your business internally and want to turn your WordPress site into an intranet for this purpose? Look no further, we have the solution for you. WordPress, being, indeed, the most popular site management platform, offers a set of tools easily exploitable by all. The platform offers, for example, the possibility of managing the source codes of the site or just installing an extension to add functionalities. Our team has also used our expertise to develop an extension for the WordPress intranet. In this article, we explain how to transform WordPress into an intranet. For this, we will offer you two approaches: an approach for developers (without extension) and another with extension (no code).

Turn WordPress into an intranet without a plugin

Being able to turn your WordPress site into an intranet without using a plugin will require some level of code manipulation. Therefore, you will need to have web development skills to choose this alternative. Here we will show you the procedure in detail. However, it is important to mention that what you intend to do with it depends on your need. In particular, some business leaders will want an intranet as a private communication channel. For others, it will be an online training portal. Thus, your approach will be guided by your need. In the following, we will look at a few lines of code to restrict access to your WordPress content, and therefore turn your WordPress site into an intranet.

1 – Create a redirect to send visitors back to the login page

To achieve this, you can either create a custom login page using the wp_login_form function or simply redirect your users to the WordPress login page. Here is an example of code that you potentially use.

<?php
/**********************************************
 *         Option for a custom login Page
 * 
 * *************************************/
 
 
function redirect_non_logged_in_users() {
    $login_id = 10; 
    $registration_id = 11;
    if (!is_user_logged_in() && !is_page($login_id) && !is_page($registration_id)) {
        wp_redirect(get_permalink($login_id));
        exit;
    }
}
add_action('template_redirect', 'redirect_non_logged_in_users');



/**********************************************
 *  redirect users to the default login
 * 
 * *************************************/
 
 
 function redirect_non_logged_in_users() {
    if (!is_user_logged_in()) {
        wp_redirect(wp_login_url( get_permalink() ));
        exit;
    }
}
add_action('template_redirect', 'redirect_non_logged_in_users');
?>
The code is structured in two parts, for two possible situations. The first is for when you would like to have a custom login page. However, in the second case, users will be redirected to the default WordPress login page. If you are using a custom page for login to your WordPress website, you can, among other things, create a shortcode to display the login form on the login page. This is, in fact, what we will show you in the following.

2- use the wp_login_form function to add the form to a custom page

Using this function, you create a shortcode that will run on the login page. It will then be a question of replacing the link of the default login page with the link of your page. In this case, you can exclude the login page from the redirect (see the first function).
function redirect_non_logged_in_users ( ) { $login_id = 10 ; $registration_id = 11 ; if ( ! is_user_logged_in ( ) && ! is_page ( $login_id ) && ! is_page ( $registration_id ) ) { wp_redirect ( get_permalink ( $login_id ) ) ; exit ; } } add_action ( 'template_redirect' , 'redirect_non_logged_in_users' ) ;
In the function above, it is assumed that the login page has the identifier "10". The function for the login page will then be similar to the code below.
 function wpdocs_log_me_shortcode_fn() {
ob_start(); 
if(!empty($this->custom_id('d'))) {
$url = get_permalink($this->custom_id('d'))."?clear=".uniqid(); 
} else {
$url = get_permalink( get_the_ID() )."?clear=".uniqid(); 
}
$args = array(
'echo' => true,
'redirect' => $url,
'remember' => true,
'value_remember' => true,
);

wp_login_form($args);
return ob_get_clean();
}

add_shortcode( 'wpdocs_log_me', 'wpdocs_log_me_shortcode_fn');
Finally, you can embed the shortcode in the WordPress editor to display the form.

Use a plugin to turn WordPress into an intranet

How to turn WordPress into an intranet? Two different approaches We offer you our WordPress extension to create an intranet from your WordPress website. In addition to the tools described above, we've included features that might make your life easier.

How does it work?

The purpose of our extension, available in our extension store, is to allow you to easily create a secure intranet based on WordPress. Without having to touch any code, you will have a satisfactory result just in a few clicks. Here are the steps to follow:
  • Install the extension on your website
  • Perform basic configurations (selection of account creation and login page)
  • Do not opt for the login page if your website does not allow login
  • Select the control panel page (if you want your users to have a dedicated panel).
Once you have done the configuration, users will be automatically redirected to the login page (if they are not logged in).

Other alternatives to turn WordPress into an intranet (with a plugin)

Generally speaking, to turn a WordPress site into an intranet, you need to restrict access to your site to authorized users only. Here are the steps to achieve this:

Install an access restriction plugin

There are several WordPress plugins that allow you to restrict access to your site. Among the most popular are “Restricted Site Access” and “WP Private Content Plus”. Install one of these plugins from your WordPress dashboard by going to Plugins > Add.

Configure Access Restriction Plugin

After installing and activating the plugin, you need to configure it to restrict access to your site. For “Restricted Site Access”:
  • Go to Settings > Playback.
  • Scroll down to the "Site Access" section.
  • Select the “Restrict site access to logged-in visitors” option and save the changes.
For “WP Private Content Plus”:
  • Go to Settings > WP Private Content Plus.
  • Configure access restrictions by choosing which parts of the site to protect.
  • Save changes.

Create user accounts

To allow your employees or members of your organization to access the intranet, you must create user accounts for them. To achieve this, go to Users > Add and fill in the required information for each user. Furthermore, be sure to set the appropriate role for each user (administrator, editor, author, contributor, or subscriber) based on the desired permissions.

Install a secure connection plugin (optional)

To increase the security of your intranet, you can install a secure login plugin, such as “Two Factor Authentication” or “Google Authenticator - Two Factor Authentication (2FA)”. This will add an extra layer of security by requiring two-factor authentication to log into the site.

Inform your users

Communicate the connection information to your users (usernames and passwords) and inform them of the URL of your intranet. They will need to log in with this information to access the site. After following these steps, your WordPress site should be transformed into an intranet and accessible only to authorized users. For all your questions or if you just want to know more, contact us.

We use cookies to ensure that we give you the best experience on our website. By continuing to use this site, you consent to our use of cookies.

Our policy