How to Import / Export WordPress Theme Customizer Settings

Do you want to import or export theme customizer settings in WordPress? Exporting and importing theme customizer settings allow you to use the same configuration on another WordPress site. In this article, we will show you how to easily import / export WordPress theme customizer… Read More »

The post How to Import / Export WordPress Theme Customizer Settings appeared first on WPBeginner.

Do you want to import or export theme customizer settings in WordPress? Exporting and importing theme customizer settings allow you to use the same configuration on another WordPress site. In this article, we will show you how to easily import / export WordPress theme customizer settings.

Import / export theme customizer settings in WordPress

Why Import / Export WordPress Theme Customizer Settings?

Many WordPress themes allow you to set up your website using theme customizer. It allows you to change colors, header images, background images, choose layout settings, and more.

Some paid and free themes have more settings available in customizer, while others have just a few basic options.

If you were working on customizing the theme on a local server or staging site, then wouldn’t it be nice if you could just move those settings to the live site?

This will allow you to move theme customizer settings from one website to another without having to move content and database.

That being said, let’s take a look at how to easily import / export theme customizer settings in WordPress.

How to Import / Export Theme Customizer Settings in WordPress

First thing you need to do is install and activate the Customize Export/Import plugin on both sites where you want to export/import. For more details, see our step by step guide on how to install a WordPress plugin.

First let’s export the theme customizer settings.

You need to go to Themes » Customize page on the website you want to export from.

Export/Import option in Customizer

Next, you need to click on the ‘Export/Import’ panel to view its settings and then click on the ‘Export’ button.

Export customizer settings

The plugin will now export your customizer settings and send them to your browser in a .dat file.

It can export all your theme options that are defined as theme mods or stored as options in WordPress database. This means you can export things like color settings, layout directions, header media, etc.

However, it will not export your navigation menus, site title and description, widgets, and more.

To import customizer settings, head over to the WordPress site where you want to import these settings.

You need to go to Appearance » Customize page and click on the Export/Import panel.

After that you need to click on the ‘Choose file’ button to select the file you exported earlier. You also need to check the box next to ‘Download and import image files?’ option to import header and other image files.

Import theme settings
Next, click on the ‘Import’ button to start uploading.

The plugin will now import the customizer settings from your export file.

Once it is finished, you can review your changes in the customizer and then click on the ‘Save & Publish’ button to make those changes live.

The plugin only exports theme settings saved using theme customizer and does not export site data like menus, widgets, images, and more. You will have to manually setup those changes.

We hope this article help you find an easier way to import/export theme customizer settings in WordPress. You may also want to see our checklist of things you must do when changing WordPress themes.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Import / Export WordPress Theme Customizer Settings appeared first on WPBeginner.

How to Restrict Media Library Access to User’s Own Uploads in WordPress

By default, WordPress allows authors to see all images on your site’s media library. This could be problematic if you invite a lot of guest authors. In this article, we will show you how to restrict WordPress media library access to user’s own uploads. Why… Read More »

The post How to Restrict Media Library Access to User’s Own Uploads in WordPress appeared first on WPBeginner.

By default, WordPress allows authors to see all images on your site’s media library. This could be problematic if you invite a lot of guest authors. In this article, we will show you how to restrict WordPress media library access to user’s own uploads.

Restrict WordPress media library access to user's own uploads

Why Restrict Media Library Access to User’s Own Uploads?

WordPress allows authors to see all files in the media library. They can also see images uploaded by an administrator, editor, or other authors.

To learn more, see our article on WordPress user roles and permissions.

Let’s say you are creating a new post to announce an upcoming product or deal. Authors and guest authors on your website will be able to see the images you upload to that article in the media library.

Your uploads will also be visible on the ‘Add Media’ popup which users see when adding images to their own articles.

For many websites, this may not be a big deal. However, if you run a multi-author website, then you may want to change this.

Let’s take a look at how to easily restrict media library access to user’s own uploads.

Method 1: Restrict Media Library Access Using a Plugin

This method is easier and is recommended for all users.

First thing you need to do is install and activate the Restrict Media Library Access plugin. For more details, see our step by step guide on how to install a WordPress plugin.

This plugin works out of the box, and there are no settings for you to configure.

Upon activation, it filters the media library query to see if the current user is an administrator or editor. If the user role does not match either of them, then it will only show user’s own uploads.

Users with the administrator or editor user role will be able to see all media uploads as usual.

Method 2: Restrict Media Library Access Manually

The first method would work for most websites as it limits media library access and allows only administrator and editor to view all media uploads.

However, if you want to add a custom user role or simply don’t want to use a plugin, then you can try this method instead. It uses the same code used by the plugin, but you will be able to modify it to meet your needs.

This method requires you to add code to your WordPress files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

You’ll need to add the following code to your WordPress functions.php file or a site-specific plugin.

// Limit media library access
 
add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' );

function wpb_show_current_user_attachments( $query ) {
    $user_id = get_current_user_id();
    if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts
') ) {
        $query['author'] = $user_id;
    }
    return $query;
} 

This code uses current_user_can function to check if the user has the capability to activate plugins or edit other user’s posts. If they don’t, then it changes the query used to display media files and limit it to user’s ID.

We hope this article helped you learn how to restrict WordPress media library access to user’s own uploads. You may also want to limit authors to their own posts in WordPress admin area.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Restrict Media Library Access to User’s Own Uploads in WordPress appeared first on WPBeginner.

How to Show Weather Forecast in WordPress

Do you want to show weather forecast in WordPress? Some website owners may want to display weather forecast to keep their users informed about weather conditions for specific locations. In this article, we will show you how to easily show weather forecast in WordPress. Why… Read More »

The post How to Show Weather Forecast in WordPress appeared first on WPBeginner.

Do you want to show weather forecast in WordPress? Some website owners may want to display weather forecast to keep their users informed about weather conditions for specific locations. In this article, we will show you how to easily show weather forecast in WordPress.

Showing weather forecase in WordPress

Why and Who Needs Weather Forecast in WordPress?

Not all websites need to display weather forecast to their users. However, there are many industries that rely on people making decisions based on this information.

This includes travel, events, hotels, bed & breakfasts and many others in the hospitality and tourism industry.

There are plenty of WordPress plugins that can pull weather information and display it beautifully on your website. You need to use a plugin that is fast, clutter-free, and doesn’t add links to weather services.

That being said, let’s take a look at how to easily show weather forecast in your WordPress posts, pages, or a sidebar widget.

Adding Weather Forecast in WordPress

First thing you need to do is install and activate the WP Cloudy plugin. For more details, see our step by step guide on how to install a WordPress plugin.

WP Cloudy can work without an API key. However, it is recommended to create an OpenWeatherMap API key to avoid timeouts.

Simply head over to OpenWeatherMap website and click on the sign up link.

Sign up for open weather map api key

After sign up, you need to visit your profile page and click on the API Keys tab. You will be asked to provide a name for your keys and then click on the ‘Generate’ button.

Generate API Key

Open Weather Map will now generate an API key for you to use. You need to copy the API key.

Next, you need to head over to Settings » WP Cloudy page in your WordPress admin area and click on the ‘Advanced’ tab.

Enter api key

On this screen, you need to scroll down to the ‘Open Weather Map API key’ option and paste the API key you copied earlier.

Don’t forget to click on save changes button to store your settings.

You are now ready to create your weather reports. You can do this by visiting Weather » Add New page to create your first weather report.

Creating a weather report

Simply enter the city, state, and country information and then switch to the ‘Display’ tab. Here you can configure different display settings. You can add / remove information that you want to show and configure the number of days to show in the forecast.

Display settings

Once you are finished, click on the publish button to save your weather report and then copy the shortcode.

Copy the weather shortcode

You can now add this shortcode to any WordPress post or page. You can also add this shortcode to a sidebar widget.

After that, you can view your website to see the weather forecast in action.

Weather forecaste displayed on a WordPress website

We hope this article helped you learn how to show weather forecast in your WordPress posts, pages, or sidebar widgets. You may also want to see our list of must have WordPress plugins for any website.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Show Weather Forecast in WordPress appeared first on WPBeginner.

How to Properly Add JavaScripts and Styles in WordPress

Do you want to learn how to properly add JavaScripts and CSS stylesheets in WordPress? Many DIY users often make the mistake of directly calling their scripts and stylesheets in plugins and themes. In this article, we will show you how to properly add JavaScripts… Read More »

The post How to Properly Add JavaScripts and Styles in WordPress appeared first on WPBeginner.

Do you want to learn how to properly add JavaScripts and CSS stylesheets in WordPress? Many DIY users often make the mistake of directly calling their scripts and stylesheets in plugins and themes. In this article, we will show you how to properly add JavaScripts and stylesheet in WordPress. This will be particularly useful for those who are just starting to learn WordPress theme and plugin development.

Properly adding JavaScripts and styles in WordPress

Common Mistake When Adding Scripts and Stylesheets in WordPress

Many new WordPress plugins and theme developers make the mistake of directly adding their scripts or inline CSS into their plugins and themes.

Some mistakenly use the wp_head function to load their scripts and stylesheets.

<?php
add_action('wp_head', 'wpb_bad_script');
function wpb_bad_script() {
echo 'jQuery goes here';
}
?>

While the above code may seem easier, it is the wrong way of adding scripts in WordPress, and it leads to more conflicts in the future.

For example, if you load jQuery manually and another plugin loads jQuery through the proper method, then you have jQuery being loaded twice. If it is loaded on every page, then this will negatively affect WordPress speed and performance.

It is also possible that the two are different versions which can also cause conflicts.

That being said, let’s take a look at the right way of adding scripts and stylesheets.

Why Enqueue Scripts and Styles in WordPress?

WordPress has a strong developer community. Thousands of people from around the world develop themes and plugins for WordPress.

To make sure that everything works properly, and no one is stepping on another’s toes, WordPress has an enqueuing system. This system provides a programmable way of loading JavaScripts and CSS stylesheets.

By using wp_enqueue_script and wp_enqueue_style functions, you tell WordPress when to load a file, where to load it, and what are its dependencies.

This system also allow developers to utilize the built-in JavaScript libraries that come bundled with WordPress rather than loading the same third-party script multiple times. This reduces page load time and helps avoid conflicts with other themes and plugins.

How to Properly Enqueue Scripts in WordPress?

Loading scripts properly in WordPress is very easy. Below is an example code that you would paste in your plugins file or in your theme’s functions.php file to properly load scripts in WordPress.

?php
function wpb_adding_scripts() {

wp_register_script('my_amazing_script', plugins_url('amazing_script.js', __FILE__), array('jquery'),'1.1', true);

wp_enqueue_script('my_amazing_script');
}
 
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );  
?>

Explanation:

We started by registering our script through the wp_register_script() function. This function accepts 5 parameters:

  • $handle – Handle is the unique name of your script. Ours is called “my_amazing_script”
  • $src – src is the location of your script. We are using the plugins_url function to get the proper URL of our plugins folder. Once WordPress finds that, then it will look for our filename amazing_script.js in that folder.
  • $deps – deps is for dependency. Since our script uses jQuery, we have added jQuery in the dependency area. WordPress will automatically load jQuery if it is not being loaded already on the site.
  • $ver – This is the version number of our script. This parameter is not required.
  • $in_footer – We want to load our script in the footer, so we have set the value to be true. If you want to load the script in the header, then you would make it false.

After providing all the parameters in wp_register_script, we can just call the script in wp_enqueue_script() which makes everything happen.

The last step is to use wp_enqueue_scripts action hook to actually load the script. Since this is an example code, we have added that right below everything else.

If you were adding this to your theme or plugin, then you can place this action hook where the script is actually required. This allows you to reduce the memory footprint of your plugin.

Now some might wonder why are we going the extra step to register the script first and then enqueuing it? Well, this allows other site owners to deregister your script without modifying the core code of your plugin.

Properly Enqueue Styles in WordPress

Just like scripts, you can also enqueue your stylesheets. Look at the example below:

<?php
function wpb_adding_styles() {
wp_register_style('my_stylesheet', plugins_url('my-stylesheet.css', __FILE__));
wp_enqueue_style('my_stylesheet');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_styles' );  
?>

Instead of using wp_enqueue_script, we are now using wp_enqueue_style to add our stylesheet.

Notice that we have used wp_enqueue_scripts action hook for both styles and scripts. Despite the name, this function works for both.

In the examples above, we have used plugins_url function to point to the location of the script or style we wanted to enqueue.

However, if you are using the enqueue scripts function in your theme, then simply use get_template_directory_uri() instead. If you are working with a child theme, then use get_stylesheet_directory_uri().

Below is an example code:

<?php
 
function wpb_adding_scripts() {
wp_register_script('my_amazing_script', get_template_directory_uri() . '/js/amazing_script.js', array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
 
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );  
?>

We hope this article helped you learn how to properly add jacvascript and styles in WordPress. You may also want to study the source code of the top WordPress plugins for some real life code examples.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Properly Add JavaScripts and Styles in WordPress appeared first on WPBeginner.

How to Lazy Load Gravatars in WordPress Comments

Do you want to lazy load Gravatars on your WordPress site? Gravatars cause extra http requests which slows down your site’s page load speed particularly on articles with a lot of comments. In this article, we will show you how to lazy load Gravatars in… Read More »

The post How to Lazy Load Gravatars in WordPress Comments appeared first on WPBeginner.

Do you want to lazy load Gravatars on your WordPress site? Gravatars cause extra http requests which slows down your site’s page load speed particularly on articles with a lot of comments. In this article, we will show you how to lazy load Gravatars in WordPress comments and improve your website speed.

Lazy Load Gravatar Images in WordPress

What is a Gravatar?

Gravatar are user profile images used by WordPress. These images are used in WordPress comments and author bio sections.

A user needs to create an account on Gravatar website and submit a profile photo for their email address.

Each time they use that particular email address, WordPress powered websites can automatically fetch their profile photo from the Gravatar website.

To learn more, see our guide on what is a Gravatar and why you should start using it.

Gravatars are great, but they can also affect your site’s page load time.

Each user gravatar adds a HTTP request to your page load. This increases the page wait time for your website and affects user experience.

Cross domain HTTP requests to fetch gravatar images

If you have a website that receives a lot of comments, then it is worth considering lazy loading the gravatar images. Let’s take a look at how to easily lazy load gravatars in WordPress comments.

Lazy Load Gravatrs in WordPress Comments

First thing you need to do is install and activate the BJ Lazy Load plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings » BJ Lazy Load page to configure plugin settings.

BJ Lazy Load settings

The plugin allows you to lazy load content, widgets, images, post thumbnails, iframes, and gravatars. You need to select the items you want to lazy load on your website.

Don’t forget to click on the save settings button to store your changes.

You can now visit any article with comments on your website. As you scroll down, you will notice lazy loading of gravatar images.

We hope this article helped you lazy load gravatars in WordPress comments. You may also want to see our ultimate guide on how to speed up WordPress and boost performance.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Lazy Load Gravatars in WordPress Comments appeared first on WPBeginner.

7 Best WordPress Ad Management Plugins and Solutions

Are you looking for the best ad management plugins and tools for WordPress? Many WordPress site owners rely on advertisements to monetize their websites. In this article, we will share the best ad management plugins and solutions for WordPress to optimize your advertising revenue. Why… Read More »

The post 7 Best WordPress Ad Management Plugins and Solutions appeared first on WPBeginner.

Are you looking for the best ad management plugins and tools for WordPress? Many WordPress site owners rely on advertisements to monetize their websites. In this article, we will share the best ad management plugins and solutions for WordPress to optimize your advertising revenue.

Ad Management plugins and solutions for WordPress

Why Use an Ad Management Plugin in WordPress?

Many websites and blogs rely heavily on advertisements to make money online with their content. By default, WordPress does not come with an easy mechanism to manage your ads.

Most WordPress themes don’t even have dedicated spots to display ads. This means you often have to edit theme files to insert ad code into your website.

A proper WordPress ad management plugin allows you to easily insert ads anywhere on your website. This helps you optimize ad placement and make most out of your advertising real estate.

That being said, let’s take a look at some of the top ad management WordPress plugins and how they can help you boost your earnings.

1. AdSanity

AdSanity

AdSanity is a beginner friendly WordPress ad management plugin. It allows you to easily insert ads anywhere on your website using widgets and ad inserter button in the visual editor.

It supports both hosted ads (banner ads managed and sold directly by you) as well as external ad networks like Google Adsense. It also comes with powerful features like ad scheduling, ad groups, insert single ad or ad group, monitor views/stats, and more.

You can create as many ads as you want and easily add them with custom widgets, shortcodes, or using the button on the post editor. You can also insert ad blocks in specific posts in WordPress. This allows you optimize ad performance without editing your WordPress theme files.

To learn more, see our article on how to manage ads in WordPress with AdSanity.

2. AdRotate

AdRotate

AdRotate is another powerful WordPress ad management plugin suitable for beginners as well as advanced users. It supports both hosted ads with rotating banner ads and network ads.

It allows you to easily create ads and ad groups and insert them into your WordPress posts using shortcodes. You can also insert ads into sidebars using custom widgets. It offers basic stats to monitor ad impressions, which is particularly helpful if you are directly selling advertisements on your website.

It is available as a free plugin, which works fine for most small blogs and websites. You will need their pro version if you want to use advanced features like scheduling, geo targeting, Adblock disguise, mobile adverts, media/asset management, and more.

For details, see our article on managing ads in WordPress with AdRotate.

3. OIO Publisher

OIO Publisher

OIO Publisher is an ad manager tool available as a plugin for WordPress powered websites. It is particularly great for growing websites that want to directly sell ad spots to advertisers. OIO Publisher will eliminate the middleman by directly selling ads through your website.

It handles reporting, payments, and tracking. You can create ad zones of different sizes and types on your website. You can choose how many ads to display in each zone, select a price, rotation factor, targeting, and more.

As a plugin, OIO Publisher is pretty straight-forward to use. It comes with a custom widget to display ads in widget ready areas of your website. However, for some placements you may need to edit WordPress theme files to place the ad zone code.

For more details, take a look at our article on how to manage WordPress ads with OIO Publisher.

4. Insert Post Ads

Insert Post Ads

Do you need a plugin that will help you automatically insert ads into your posts? Check out Insert Post Ads. It allows you to automatically display ads in your post content.

You can create different ads of any size and then choose after which paragraph you want to display the ad. You can also display multiple ads in the same article after different number of paragraphs.

It is really simple to use. You just need to create an ad with the ad code and then ad the paragraph number. You can add third-party ad code as well as custom HTML for your own hosted ads.

For detailed instructions, see our guide on how to insert ads within your post content in WordPress

5. DoubleClick by Google

DoubleClick by Google

DoubleClick by Google is a web based ad selling and serving platform for publishers. Powered by Google, DoubleClick gets an edge over other platforms in terms of reliability and cost effectiveness.

It also allows you to sell your ads and run competition for the same ad spots on Adsense or other third party advertisement networks. DoubleClick will automatically choose the best paying ad for the spot and serve it.

DoubleClick also includes great reporting tools that allow you to measure ad performance more accurately than other solutions. Despite its effectiveness, it’s a bit complicated to get started with.

6. Ad Inserter

Ad Inserter

Ad Inserter is a WordPress ad management plugin available in free and paid versions. The free version is good enough to be used as your primary ad management tool but for advanced features you would want to upgrade to their paid version.

It allows you to create multiple ad blocks and choose how you want to auto-insert each block. There are a number of options to insert your ad. You can add it inside post content, before and after post content, between posts, before or after post excerpt, and more.

You can also individually disable automatic ad insertion in posts and pages, home, categories, and archive pages. It is fairly easy to use and can be used for both hosted and third-party ad networks.

7. Quick Adsense

Quick Adsense

Quick Adsense is a popular free WordPress ad management plugin. Despite its name, the plugin can be used to display any kind of ads including hosted ads, third-party ad networks including Google Adsense.

It comes with an easy to setup settings page where you can manage your ad codes and select how and where you want to display them. The plugin can automatically display ads before or after articles, inside post content, after the excerpt, and more.

It has custom ad widgets to display ads in sidebars and other widget ready areas.

It does not have many advanced features part of some other plugins on this list. Another limitation is that you can only save up to 10 ad codes at a time.

We hope this article helped you find the best ad management plugins and solutions for WordPress. You may also want to see our list of the best affiliate marketing tools and plugins for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post 7 Best WordPress Ad Management Plugins and Solutions appeared first on WPBeginner.

How to Restrict WordPress Pages by User Role

Do you want to restrict WordPress pages by user role? Many WordPress businesses need to control which users can access certain pages on their websites. In this article, we will show you how to easily restrict access to certain WordPress pages by user role. Restricting… Read More »

The post How to Restrict WordPress Pages by User Role appeared first on WPBeginner.

Do you want to restrict WordPress pages by user role? Many WordPress businesses need to control which users can access certain pages on their websites. In this article, we will show you how to easily restrict access to certain WordPress pages by user role.

Restrict Content by User Role

Restricting WordPress Pages by User Role

By default, WordPress comes with a limited set of tools to restrict content on your website. You can create private and password protected posts, but these features don’t allow you to limit access by user role.

Luckily, there are several WordPress plugins that allow you to do just that. You can choose one of them to restrict pages to certain users, user groups, or user roles.

Using these plugins, you can create a membership website, pay-per-view websites, or even family blogs. You can also monetize your content by adding paid subscriptions.

That being said, let’s take a look at how to properly restrict WordPress pages by user role. We will be showing you different plugins, you can choose the one that best suits your needs.

1. Restrict Content Pro

Restrict Content Pro

Restrict Content Pro is a great option to control who has access to your website content. It also allows you to add paid subscriptions and make money online from your membership website.

First, you will need to install and activate the Restrict Content Pro plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Restrict » Settings page to enter your license key. You can get this key from your account on Restrict Content Pro website.

Enter your license key

Next, you need to switch to the payments tab to select a payment gateway.

Restrict Content Pro allows you to accept payments through PayPal, Stripe, 2Checkout, Braintree, and Authorize.net.

Payments

After selecting a payment method, you will be able to add credentials for each Payment method.

Don’t forget to click on the save options button to store your settings.

Now you need to edit the pages or posts you want to be restricted by user roles.

On the edit screen, scroll down to ‘Restrict this content’ meta box and select ‘Members with certain role’ option.

Restrict content by user role

Choose the user role you want to allow and then update or publish your content.

Restrict Content Pro also allows you to create subscription levels. For more detailed instructions, see our guide on how to restrict content to registered users in WordPress.

2. MemberPress

MemberPress

MemberPress is one of the best WordPress membership plugins in the market. It allows you to easily create membership websites with paid subscriptions.

First you will need to install and activate the MemberPress plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, head over to MemberPress » Activate page to enter your license key. You can find this information from your account on MemberPress website.

MemberPress license key

Next, you need to click on the Add-Ons tab and install ‘WordPress User Roles’ add-on.

User role addon

After installing the user role add-on, you need to head over to MemberPress » Options page. Click on the payments tab to set up payments.

Set up payment gateway for MemberPress

MemberPress supports PayPal (Standard, Express, and Pro), Stripe, and Authorize.net out of the box. Select the payment methods you want to use and provide the required credentials.

Next, you need to visit MemberPress » Memberships page and click on the ‘Add New’ button to create a membership plan.

Creating a membership

You will start by providing a title for this membership plan and set pricing, billing type, and expiration settings.

After that, scroll down to the ‘Membership Options’ meta box below the post editor. This is where you can setup different options for this particular membership plan.

Membership options

Click on the ‘Advanced’ tab under membership options and choose a user role for this membership plan.

Select user role for membership plan

Be careful when choosing a user role as each user role in WordPress comes with its own permissions. If you need you can also create a custom user role for the membership plans on your website.

You can now publish your membership plan.

If you want to add more membership plans, then you can repeat the process to add them.

Once you have created membership plan(s). It is time to set up rules to restrict access to the content.

Head over to MemberPress » Rules page and click on the Add New button at the top.

This will bring you to the rules edit page where you can select different conditions and associate them to a membership plan.

Setting rules

For example, you can select all content that matches a particular tag or category to be available only to members with a membership plan you created earlier.

Lastly, you need to edit the content you want to restrict and add it to that particular category or tag.

That’s all, you have successfully restricted pages in WordPress by user role and membership.

3. LearnDash

LearnDash

LearnDash is the best WordPress LMS plugin. It allows you to create and sell courses online.

It comes with built-in subscriptions allowing users to enroll into a course before they can see its contents. This enables you to restrict access to course pages and monetize your website.

First thing you need to do is install and activate LearnDash plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit LearnDash LMS » Settings page and click on the LMS License tab. Enter your LearnDash account email address and license key, and then click on ‘Update License’ button to save it.

LearnDash license

Next, you need to switch to the ‘PayPal Settings’ tab to enter your PayPal email address.

LearnDash payment

By default, LearnDash only offers PayPal payment gateway. Stripe and 2Checkout are available as extensions.

Now you can go to LearnDash LMS » Courses page and click on the ‘Add New’ button to add your first course.

Add new course

Enter a title and description for your course. The description part will be visible to all users to explain what this course is about.

Add course title and description

After that you need to scroll down to the course options meta box. Under the course price type option, you can select an access option for the course.

The plugin allows you to create open (public) or closed courses, free, buy bow, and recurring price types.

Course options

For free courses, your users will still need to enroll into course by creating account.

You can now save or publish your course and preview it on your website.

Preview course page

Now that you have created a course, it is still empty. To fill it up you will need to add the course contents like lessons, quizzes, and assignments.

LearnDash is a powerful tool to sell online courses while restricting access to content. It works really well with MemberPress to create subscription plans that automatically give users access to different courses.

That’s all for now. We hope this article helped you learn how to easily restrict WordPress pages by user role. You may also want to see our ultimate step by step WordPress security guide for beginners.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Restrict WordPress Pages by User Role appeared first on WPBeginner.

How to Automatically Post New Instagram Photos to WordPress

Do you want to automatically post new Instagram photos to your WordPress site? Instagram is an influential platform that can be used to drive traffic to your website. In this article, we will show you how to automatically post new Instagram photos to WordPress. Why… Read More »

The post How to Automatically Post New Instagram Photos to WordPress appeared first on WPBeginner.

Do you want to automatically post new Instagram photos to your WordPress site? Instagram is an influential platform that can be used to drive traffic to your website. In this article, we will show you how to automatically post new Instagram photos to WordPress.

Instagram and WordPress

Why Post Instagram Photos to WordPress?

Instagram allows people to discover new user accounts based on what they already like. Users can also explore profiles by hashtags, location, and sharing.

If you have just started on Instagram, then you may find it a bit slow to get followers. You need social proof to build traction.

Sharing your Instagram photos on your WordPress website works both ways. You can help users find you on Instagram. Once they start following you, then you can keep them engaged with your brand.

That being said, let’s take a look at how to easily and automatically post new Instagram photos to WordPress.

Method 1: Add Instagram Photos as a New Post in WordPress

This method is for users who want to create a new blog post displaying their latest Instagram photo.

First you need to visit IFTTT website and login or create a new account. IFTTT is an online tool that allows you to automate your social media and WordPress.

After you’re logged in, you need to click on My Applets » New Applet to get started.

Create new applet

First you need to click ‘+this’ and then locate Instagram to activate it.

This will bring up a popup where you will be asked to log in to your Instagram account and authorize IFTTT to access your account.

Authorize IFTTT to access Instagram

Next, you will be asked to choose a trigger. Click on ‘Any new photo by you’ to continue.

Choose trigger

After that you will see ‘If this then +that’ statement. Click on the +that to select what you want to do with the new photo.

On the next screen, locate WordPress to add it as the action service.

Choose WordPress as action service

IFTTT will now ask you to connect your WordPress site as a service. Clicking connect will bring up a popup where you need to enter your WordPress site’s URL, admin username, and password.

Connect WordPress

Next you need to select what action you want to take. You can either create a blog post with the new Instagram photo or a photo post.

Choose Action

After that you’ll be asked to map Instagram fields to your WordPress post. You can add tags, add custom caption, and more.

Map fields

Once you are done, click on the finish button to save your applet.

You can now post a new photo to your Instagram account, and it will be automatically posted to your WordPress site.

Instagram photo posted in WordPress

Method 2: Display Latest Instagram Photos on Your WordPress Site

This method is for users who just want to show their latest Instagram photos without creating new blog posts.

First thing you need to do is install and activate the Instagram Feed plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, the plugin will add a new menu item labeled Instagram Feed to your admin bar. Clicking on it will take you to the plugin’s settings page.

Get access token and user ID from Instagram

First you need to authenticate the plugin to access your Instagram profile. Click on the blue button to login and get the access token and user ID from Instagram.

You will be asked to log in to your Instagram account. After that you will need to authorize the WordPress plugin to access your Instagram account.

Authorize plugin to access Instagram data

On the modal popup, click on the authorize button to continue.

You will now be redirected back to the plugin’s settings page on your WordPress site with access key and user ID. Don’t forget to click on the save changes button to store your settings.

Displaying Instagram Photos on Your WordPress Site

Instagram Feed makes it super easy to display your Instagram photos anywhere on your WordPress site.

Simply edit the WordPress post or page where you want to display your Instagram photos and add the following shortcode:

[instagram-feed]

You can now save your changes and preview your post or page.

Instagram preview

You can change the number of columns by modifying the shortcode like this:

[instagram-feed cols=3]

You can also add shortcode to a sidebar widget to display your Instagram photos in the sidebar.

Instagram sidebar preview

Customizing Your Instagram Feed

Instagram Feed plugin also allows you to easily change the appearance of your photos.

Go to plugin’s settings page and then click on the ‘Customize’ tab.

Customize Instagram feed

Here you can change the feed’s height, width, layout, background color, and more.

We hope this article helped you automatically post new Instagram photos to your WordPress site. You may also want to see our list of the best social media monitoring tools for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Automatically Post New Instagram Photos to WordPress appeared first on WPBeginner.

How to Show Total Number of Posts in WordPress

Do you want to show the total number of posts on your WordPress site? Showing total number of articles may help showcase the consistency of your blog and encourages users to look for more content. In this article, we will show you how to easily… Read More »

The post How to Show Total Number of Posts in WordPress appeared first on WPBeginner.

Do you want to show the total number of posts on your WordPress site? Showing total number of articles may help showcase the consistency of your blog and encourages users to look for more content. In this article, we will show you how to easily display total number of posts in WordPress.

Show total number of posts in WordPress

Method 1: Show Total Number of Posts in WordPress Using a Plugin

This method is easier and recommended for all users.

First thing you need to do is install and activate the Simple Blog Stats plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation you need to visit Settings » Simple Blog Stats to configure plugin settings.

Simple Blog Stats plugin shows you useful WordPress stats like total number of comments, users, pages and posts. You can easily display these stats using shortcodes anywhere on your WordPress site.

Blog stats shortcodes

Simply copy the [sbs_posts] shortcode and add it to any WordPress post, page, or shortcode enabled sidebar widget.

It will show the total number of published posts on your WordPress site.

number of posts

You can also use [sbs_blog_stats] which will show all blog stats including the total number of posts.

Blog stats

Method 2. Manually Display Total Number of Posts in WordPress

This method requires you to add code to your WordPress site. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

First you need to add this code to your theme’s functions.php file or a site-specific plugin.

function wpb_total_posts() { 
$total = wp_count_posts()->publish;
echo 'Total Posts: ' . $total;
} 

This code simply output the total number of posts whenever the template tag wpb_total_posts is called.

Next, you need to add <?php wpb_total_posts(); ?> in your theme files where you want to display total number of posts.

If you don’t want to use the template tag, then you can create and use a shortcode that does exactly the same thing.

Copy and paste the following code to your theme’s functions.php file or a site-specific plugin to create a shortcode:

function wpb_total_posts() { 
$total = wp_count_posts()->publish;
return $total; 
} 
add_shortcode('total_posts','wpb_total_posts');

Now you can use the shortcode [total_posts] to display total number of posts in any posts, pages, or sidebar widgets.

We hope this article helped you learn how to show total number of posts in WordPress. You may also want to see our mega list of most wanted WordPress tips, tricks, and hacks.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Show Total Number of Posts in WordPress appeared first on WPBeginner.