How to Prevent Changes to Plugins, Themes, and WordPress Core Files

Category Image 091

This is a common question I get from folks in the WordPress community. How can I “lock things down” and prevent any changes to plugins, themes, and WordPress core files. For example, how to prevent any themes and/or plugins from being updated or deleted, and how to prevent any new plugins from being installed. This is useful for certain projects where it’s necessary to lock a website to a static version. Fortunately, WordPress makes this super easy with a couple of PHP constants. Let’s take a quick look..

Contents

Prevent Changes via File Editor

Did you know that WordPress provides a Plugin File Editor and Theme File Editor in the WP Admin Area. You can find them:

  • Under the Appearance menu ▸ Theme File Editor
  • Under the Plugins menu ▸ Plugin File Editor

These tools enable admins to make changes to any plugin or theme files. Huge convenience for those that need it. For those that don’t, you can disable any changes via the file editors by adding the following line to your site’s wp-config.php file, which resides in the root WordPress directory:

// disable file changes via plugin and theme editors
define('DISALLOW_FILE_EDIT', true);

Once this line is included in the site’s configuration file, all file-editing via the Admin Area will be disabled. No menu items, no editing, nada. It’s another layer of security that effectively minimizes your site’s attack surface, so sensitive files cannot be modified by any user, including admins. This helps to protect against any changes that could compromise or crash your site.

Note: As explained at WordPress.org, disabling the file editors via DISALLOW_FILE_EDIT constant may affect any plugins that check for sufficient capabilities using current_user_can('edit_plugins'). Plugins should check if the constant is set, and if so display an appropriate error message.

Prevent All Changes via Admin Area

While the previous technique disables changes to plugins and themes via the file editors, this next technique prevents all changes to any files from inside the Admin Area. This includes:

  • Updating, deleting, installing plugins
  • Updating, deleting, installing themes
  • Updating the WordPress core files

It also includes changes made via the plugin and theme file editors. Basically this technique staticizes a site to its current version. So if that sounds like you, here is the magic code to lock it down:

// disable all changes to all files via admin area
define('DISALLOW_FILE_MODS', true);

Once this line is included in the site’s configuration file, all changes (installing, updating, deleting) to plugins and themes will be disabled. Note that the above line also disables updates to the WordPress core files, so trying to update WordPress via Dashboard ▸ Updates will not work.

Of course, it always is possible for changes to be made directly on the server via SFTP or similar method. But any file changes from within the Admin Area will be disabled completely.

Note: As mentioned, the above line disables all changes from anywhere within the Admin Area, including the file editors. So you do not need to set both DISALLOW_FILE_MODS and DISALLOW_FILE_EDIT. Just including DISALLOW_FILE_MODS takes care of everything.
Note: Be careful when adding DISALLOW_FILE_MODS to your site’s wp-config.php file. WordPress needs to be able to make changes in order to keep plugins, themes, and core files current via updates. So only disable changes if you are 100% certain that you don’t want any updates on your WordPress site.

How to Add Custom Meta Boxes in WordPress Posts and Post Types

Featured Imgs 13

Do you want to learn how to create custom meta boxes for your WordPress posts, pages, and custom post types?

WordPress adds metadata to your content automatically, such as the publication date, categories, and tags. However, you may also want to add your own custom meta data.

In this article, we will show you how to easily add unique information to your content, by creating a custom meta data box in WordPress.

How to add custom meta boxes in WordPress posts and post types

What is a Custom Meta Box in WordPress?

When you create posts and pages, or custom post types in WordPress, that content usually has its own metadata. This metadata is information related to the content like date and time, the author name, title, and more.

You can also add your own metadata using the default custom fields box.

Adding custom meta boxes in WordPress posts

Pro Tip: Can’t see the Custom Fields box in the post editor? Then see our guide on how to fix custom fields not showing in WordPress.

The Custom Fields box is a good solution if you just want to add custom metadata to a few posts. However, if you plan to add lots of unique information to your content, then it makes sense to create a custom metadata box.

In fact, many of the popular WordPress plugins add custom meta boxes to the Edit screen for posts and pages. In the following image, you can see how easy it is to add SEO information to your post, using a custom meta box provided by AIOSEO.

The All in One SEO (AIOSEO) WordPress plugin

With that being said, let’s see how you can easily add custom meta boxes in WordPress posts and post types.

How to Add Custom Meta Boxes in WordPress Posts and Post Types

The easiest way to add custom meta boxes to WordPress is by using Advanced Custom Fields. This plugin allows you to attach all kinds of extra information to your posts and pages, and then show that data to visitors using a shortcode.

The first thing you need to do is install and activate the Advanced Custom Fields plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Create a Custom Meta Box

Upon activation, go to ACF » Field Groups and then click on the ‘Add New’ button.

Adding a custom field to your WordPress website

Here, you can create the custom fields that will appear in the metadata box.

To start, you’ll need to type a title into the field that shows ‘Field Group Title’ by default. This will appear in the WordPress content editor, and it will be used as the title of your meta box.

With that being said, you should use something descriptive, especially if you manage a multi-author WordPress blog or share the dashboard with other people.

How to easily add custom meta data to your website or blog

With that done, you’re ready to add the first field to your meta box.

Add Custom Fields to the Meta Box

To start, open the ‘Field Type’ dropdown and choose the type of field you want to add, such as Text, Date Picker, Checkbox, or any other field type.

Adding custom fields to the WordPress content editor

After that, type in a label for the field.

Advanced Custom Fields will show this label before the field, so it will help users understand what information they need to enter.

The Advanced Custom Fields WordPress plugin

Advanced Custom Fields will generate the ‘Field Name’ automatically, so you can leave this field empty.

With that done, you may want to type in a ‘Default Value.’ This will be added to the page, post, or custom post type automatically if the user doesn’t add their own information.

Adding default values to custom WordPress fields

You may see more options depending on the kind of field you’re creating. For example, if you selected ‘Image’ from the ‘File Type’ dropdown, then you can choose the image format.

Most of these options are self-explanatory so you can follow the onscreen instructions to configure the custom field.

When you’re happy with how the field is set up, click on ‘Close Field’ to collapse the section.

Adding custom data to a website or blog

You can now add more fields to the custom meta box by clicking on the ‘Add Field’ button.

Then, simply configure the field by following the exact same process described above.

Saving a custom field group

Add a Custom Meta Box to the WordPress Content Editor

When you’re happy with how the custom meta box is set up, you’ll need to define where and when the meta box will appear.

Scroll to the ‘Settings’ section and then click on the ‘Location Rules’ tab.

Controlling where custom content appears in the WordPress content editor

Advanced Custom Fields can add the box to all kinds of content. For example, you can show the meta box on specific post types, categories, taxonomies, navigation menus, and more.

Simply use the dropdown menus to choose where the meta box will appear in your WordPress dashboard. For example, if you accept guest posts then you may want to add the box to all posts in the ‘Guest Posts’ category.

Creating content rules using a WordPress plugin

After that, click on the ‘Presentation’ tab.

Here, you can choose the meta box style, where it appears on your WordPress blog, and where the label and instructions will appear.

ACF's presentation settings in the WordPress dashboard

If you plan to add multiple boxes in the same location, then you can change the order they appear in by typing into the ‘Order No’ field.

For example, showing the most important meta boxes towards the top of the screen may improve your editorial workflow.

If you’re unsure, then you can leave this field set to 0.

Reorganizing fields in the WordPress content editor

On this screen, you’ll also see a list of all the fields that WordPress usually shows on the post edit screen.

If you want to hide a field, then simply check its box. For example, if you’re using custom fields to create an author info box, then you may want to hide the default ‘Author’ field.

Hiding fields in the WordPress post editor

When you’re happy with the changes you’ve made, click on ‘Save Changes’ to make the field group live.

You’ve now successfully created a custom meta box for your WordPress post, page, or custom post type. Depending on your settings, you can now visit the post editor to see the custom meta box in action.

An example of a custom meta data box, created using a free WordPress plugin

Displaying Your Custom Meta Box Data in WordPress Theme

You’ve now successfully added a custom meta box to the WordPress dashboard. Any information users type into the meta box will be stored in the WordPress database when they save or publish the post. However, this information won’t appear on your website by default.

With that in mind, let’s make sure the custom metadata appears in your WordPress theme, so visitors can see it.

You can do this using shortcode or by editing your WordPress theme files.

How to Display Custom Metadata using Shortcode

Adding a shortcode in WordPress is the easiest method, and allows you to control exactly where the information appears on your website. For example, if you’ve created a ‘Star Rating’ field, then you can show this information after the post title, inside the content, in the footer, or anywhere else simply by adding a shortcode.

However, you will need to add a shortcode to every page, post, or custom post type manually. This can take a lot of time and effort, especially if you have a lot of content.

To get a field’s shortcode, go to ACF » Field Groups. Then, hover over the field group that you want to display and click on the ‘Edit’ link when it appears.

Editing a meta data field group

You’ll now see all the fields that make up this group.

For each field you want to display, make a note of the value in the ‘Name’ field.

How to show custom data in your WordPress theme using shortcode

With that done, go to the page, post, or custom post type where you want to show the custom metadata.

You can now click on the ‘+’ icon and type in ‘Shortcode.’

Adding shortcode to a WordPress page or post

When the right block appears, click to add it to your layout.

You can now add the following shortcode to the block, making sure to replace "article_byline" with the name of the field you want to show.

Adding custom meta data to a WordPress theme

You can now repeat these steps to add multiple custom fields to the post.

When you’re happy with the changes you’ve made, either click on the ‘Publish’ or ‘Update’ button. Now, simply visit your WordPress website to see the custom metadata in action.

An example of custom meta data, displayed using a shortcode

How to Display Custom Metadata by Editing Your WordPress Theme

If you want to show custom metadata in the same location on every page, post, or custom post type, then you can add code to your WordPress theme files.

This can save you time in the long-term, but it isn’t the most beginner-friendly method. You’ll also lose all the custom code the next time you update your WordPress theme, which is why we recommend creating a child theme. You can then add your custom code to the child.

If you haven’t edited your theme files before, then take a look at our beginner’s guide on how to copy and paste code in WordPress.

You’ll need to edit the file where you want to show the custom metadata. This will vary depending on your theme, but you’ll usually need to edit your site’s single.php, content.php, or page.php file.

Once you have the right file, you’ll need to add the code inside the WordPress loop. To find this loop, simply search for code that looks something like this:

	<?php while ( have_posts() ) : the_post(); ?>

You can then paste your code after this line and before the line that ends the loop:

	<?php endwhile; // end of the loop. ?>

As an example, your custom field code should look something like this:

	<h2 class="article-byline"><?php the_field('article_byline'); ?></h2>

Notice how we wrapped the code in a h2 heading with a CSS class. This allows us to format and style the custom field later by adding custom CSS to our theme.

Here’s another example:

<blockquote class="article-pullquote">
 
<?php the_field('article_pullquote'); ?>
 
</blockquote> 

When adding code to your theme, don’t forget to replace the field names.

With that done, you can visit any post where you’ve already entered data into the custom fields. You will now see your unique metadata in action.

How to add custom fields to a WordPress theme

We hope this article helped you learn how to add custom meta boxes in WordPress posts and post types. You may also want to see our guide on how to create automated workflows in WordPress, or see our expert pick of the best SEO plugins and tools that you should use.

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 Add Custom Meta Boxes in WordPress Posts and Post Types first appeared on WPBeginner.

Comparing Free WordPress.com vs. Self-Hosted WordPress.org

Category Image 091
Choosing between a free WordPress blog and a self-hosted WordPress blog ultimately depends on your goals and needs as an Internet marketer. While the free version may be easier to set up and manage, it lacks the flexibility and control that a self-hosted blog offers. Comparison: Free Vs. Self-Hosting WordPress Blog When it comes to […]

Stay Logged in to WordPress

Category Image 091

I work from home so can afford to leave tabs open for each of my WordPress sites. That way I can jump on anytime and update or add new content very quickly. The problem I kept running into is that WordPress automatically logs out users after 48 hours. Which means I have to log back in every day even when it’s not necessary. So I needed a way to stay logged in to WordPress indefinitely. Fortunately WordPress is very flexible and easy to customize, and the login duration can be changed via several different methods.

Here are three easy ways to stay logged in to WordPress for a longer period of time.

Three ways to do it..

Check the box

The easiest way to increase the expiration date/time for logins, is to simply check the “Remember Me” checkbox when logging in to WordPress. That will increase the expiration to 14 days, or whenever the browser is closed. After that time, the session cookie expires and you’ll need to log in once again.

This is useful if 14 days is enough time for your workflow.

One downside is that it requires an extra click to check the box. Fine I guess if you’re logging in manually. But if you’re using a password manager or other auto-login app, the extra checkbox step requires action on your part, thus adding friction and slowing things down.

Another downside is that 14 days is not always enough. For my own workflow, I prefer to minimize as many needless steps as possible. So I prefer the next method of extending the login duration, using a slice of custom code..

Add custom code

For more flexibility and less friction, you can add the following code snippet to stay logged in to WordPress for however long is necessary, even indefinitely if it makes sense to do so. This is the preferred technique for my own websites.

Important: Be mindful of any other users who may be logging in on public machines. Only extend the login duration if you know 100% that it’s safe and secure.

Here is the magic code to stay logged in to the WordPress Admin Area. You can add this code via your theme functions file, or add via simple custom plugin. Here is a guide that explains how to do both.

function shapeSpace_stay_logged_in($expires) {
	
	return 172800; // default 48 hours
	
}
add_filter('auth_cookie_expiration', 'shapeSpace_stay_logged_in');

As written, this code hooks into auth_cookie_expiration and filters the expiration duration (in seconds). By default the duration is 48 hours. You can change that to anything that works best.

To stay logged in forever, change the interval to some very large number, like 3153600000 to stay logged in for 100 years ;) To help with converting time to seconds, you can use a free time conversion calculator.

Thanks to Alex Mills (Viper007Bond) for sharing this code at Stack Exchange.

Update! Thanks to Scott Fennell for pointing out that WordPress provides a set of time constants that we can use instead of typing out seconds like animals:

MINUTE_IN_SECONDS
HOUR_IN_SECONDS
DAY_IN_SECONDS
WEEK_IN_SECONDS
MONTH_IN_SECONDS
YEAR_IN_SECONDS

So we can do like 3 * HOUR_IN_SECONDS to specify a time interval of 3 hours.

Bonus: Check the “Remember” box by default

Bonus tip! To automatically check the “Remember Me” box on the WP Login Page, add the following code via theme functions or custom plugin.

function shapeSpace_custom_login_checkbox() {
	
	?>
	
	<script>
		document.getElementById('rememberme').checked = true;
		document.getElementById('user_login').focus();
	</script>
	
	<?php
	
}
add_filter('login_footer', 'shapeSpace_custom_login_checkbox');

No changes need made, just add and done. One in place, the remember checkbox will be selected automatically by default.

Install a plugin

If you want to extend the login beyond 14 days, but don’t want to go the custom code route, installing a plugin is the way to go. Currently there seems to be only a couple of capable plugins in the WP Plugin Directory:

Let me know if I’ve missed anything! :)


How to Add Custom Code to WordPress

Category Image 091

There are many books and tutorials that share useful code snippets for WordPress. For example, you can find hundreds of custom functions right here at DigWP.com. You can also find them in my WordPress books, tutorials, and code snippets. For many code snippets and custom functions, the usage instructions will say something like:

Add this code to your theme (or child theme’s) functions.php file, or add the code via simple custom plugin.

So what does that actually mean? Let’s take a closer look. First we’ll go through how to add custom code via the functions.php file. Then we’ll explain how to add code by making a simple custom plugin. Finally we’ll wrap things up by explaining the difference between the two methods and how to go further.

Contents

Add custom code via theme functions.php

Every WordPress theme can have a file named functions.php. If present in a theme, the functions file must be located in the root directory of the theme:

/wordpress/
	/wp-content/
		/themes/
			/my-theme/
				functions.php

If the functions file does not exist, create it. Then open the file in a code or text editor and add your custom code. Save the file, upload to the server, and done. It is very straightforward. Just make sure to test any new code on a private/test site before adding to a live production site.

Learn more about building themes in my book, WordPress Themes In Depth.

Add custom code via simple custom plugin

With WordPress, plugins add functionality, and themes display content. There is some overlap (and grey area), but in general the best way to add functionality to WordPress is with a plugin. That’s one reason why there are over 50,000 plugins in the WordPress Plugin Directory.

Plugins range in complexity. They can be very advanced, comprising many files and lots of code. Or they can be very simple, made with one file and a few lines of code. To add a custom code snippet, a simple plugin will suffice.

How to make a simple custom plugin

To make a simple custom plugin, follow these steps:

  1. Create a new PHP file
  2. Name the file whatever makes sense, can be any alphanumeric string (plus dashes and underscores if needed)
  3. Open the file and add the header code provided below
  4. Save the file and done

After creating this file, it is ready for your custom code snippet(s). To save you some time, I’ve created an example plugin that you can download below. It’s ready to go for any custom code that you want to add.

Download a simple custom plugin

Download a copy of our simple custom plugin, ready for your custom code.

Download Simple Custom Plugin (ZIP file < 1 KB)

Usage: Download and unzip the file. Open simple-custom-plugin.php and customize the file header as explained below. Then add your custom code snippet, save changes and done.

Plugin file header

At the beginning of your plugin file, add the following lines:

<?php 
/*
	Plugin Name: Simple Custom Plugin
	Plugin URI: https://digwp.com/2022/02/simple-custom-plugin/
	Description: This is a simple plugin template for adding custom code to WordPress.
	Author: Jeff Starr
	Author URI: https://plugin-planet.com/
	Requires at least: 5.9
	Tested up to: 5.9
	Version: 1.0
*/

if (!defined('ABSPATH')) die();

// add custom code snippets below this line..

You can customize the header lines with your actual information. As our simple plugin is meant only for your site and will not be distributed publicly, the file header can be much simpler than what’s required for plugins destined for the WP Plugin Directory. Learn more about plugin file headers at WordPress.org.

Also: notice this line:

if (!defined('ABSPATH')) die();

That line is included to prevent direct access to the file. It basically checks if WordPress is loaded; if not, the script simply exits. This is a basic security measure to help prevent anyone from meddling with your custom code.

Remember to use code snippets only from trusted sources. And then test the code on a private site before going live.

What’s the difference?

What’s the difference between adding code via theme functions vs. simple plugin? The main difference is scope. When code is added via your theme template, it will run only when the theme is active. So for example, say we add a custom code snippet that displays social media buttons on posts. If we change themes, the custom code will not run, and the buttons will not be displayed.

Contrast that with adding custom code via simple plugin. As long as the plugin is active, the custom code will run always, regardless of which theme you’re using. Going the plugin route also benefits in terms of things like extensibility and maintainability. Managing custom code via plugins generally is easier than burying it within the theme’s functions file.

So which is best? Neither. The two methods are just different. Which one is best for any given code snippet depends on various factors. Most importantly whether or not the custom code is theme specific or global in scope.

For an easy, no-fuss way to add custom code snippets, check out WPCodeBox.

Going further..

The above simple plugin example is the most basic possible. To go further with plugin development, visit the Plugin Developer Handbook at WordPress.org.

Questions and comments welcome! :)


ACF 6.0 Introduces Refreshed Admin UI and ACF Blocks Version 2

Category Image 091

Advanced Custom Fields (ACF) has announced the availability of version 6.0, an update that applies to both the free and pro versions of the plugin. This release introduces a refreshed admin UI that ACF product manager Iain Poulson said users had been requesting since 2021.

“We didn’t want this to be a huge change that would disrupt a user’s workflow, but instead a light reskin that focuses on bringing user experience improvements to the Field Group editor,” Poulson said.

“The team have done a great job with the new design, improving all the ACF plugin admin screens from the Field Group editor to the Tools page.”

The reskinning delivers the following improvements:

  • Reduces the vertical height of the field settings
  • Improved experience adding new fields to a Field Group
  • Added a sticky “Save Changes” button to the header bar that is always visible without users having to scroll up to the top of the page
  • Added more width to “Fields” box to reduce cramping from nested subfields
  • Keyboard navigation for fields
  • Improved focus states across the Field Group editor, toggle switches, radio buttons, and checkbox groups
  • New opt-in setting for Repeater pagination

Version 6.0 also includes ACF Blocks Version 2, a feature included in ACF PRO. It allows developers to use a PHP-based framework for developing custom block types.

“ACF 6.0 contains a new block versioning system, allowing you to opt in to new versions which will change things like the markup and structure of ACF Blocks in both the backend and frontend, and may require updates to your theme to support,” Poulson said.

“This next generation of ACF Blocks brings us much closer to the native block experience, while still giving you the PHP based templating language you know as a WordPress developer.”

ACF users were encouraged to see that the plugin is still moving forward after having changed hands twice in the past two years. Delicious Brains acquired ACF from its creator Elliot Condon in June 2021. By November of that year, Delicious Brains was soliciting the plugin’s Lifetime License holders for contributions via email, urging them to purchase annual subscriptions. Seven months later, Delicious Brains sold off ACF and four other products to WP Engine, rattling customers who were concerned about the plugin’s lack of innovation and its stability in the hands of a large hosting company.

Poulson, who continued on with WP Engine to support Delicious Brains’ products after they were acquired, said the next thing on the roadmap is adding the ability to register custom post types and taxonomies in the UI and improvements to how field types are selected.

Akismet 5.0 Adds New Spam Detection Feature That Analyzes How Comments Are Posted

Category Image 091

For years, the vast majority of Akismet releases have been centered around bug fixes and improving compatibility with various plugins. Version 5.0 was released today, following 4.2.5 earlier this month, with a new feature that should improve Askismet’s ability to detect spam comments.

Akismet engineer Christopher Finke explained how the plugin will now analyze how a comment is posted, in addition to analyzing what is posted:

A typical human commenter on the Web takes about 40 seconds to read a blog post and another 40 seconds to write and submit a comment. Their typing speed varies significantly throughout the creation of their comment, and they regularly use their mouse to click around the page. An automated spambot (even one programmed to act like a person) doesn’t act so human-like: its typing speed and mouseclick speed are superhumanly consistent. It doesn’t spend time “reading” blog posts. Its mouse usage is sparse.

This new feature can detect spam that is posted in a machine-like fashion, even if the spambot is attempting to post a comment with content identical to one that has already been approved.

“The Akismet plugin will begin observing these behaviors so that they can be used as part of the spam-checking process,” Finke said. “None of this data is personally identifiable, and it won’t be used for any purpose other than identifying spam.”

Akismet is bundled with WordPress and is active on more than 5 million sites. More than 62% of users are running on 4.2.x and ~38% are on version 4.1 or older. WordPress users who are having a lot of spam breaking through Akismet’s protection will want to upgrade to take advantage of the new spambot detection features in version 5.0.

How to Fix ‘Comments Are Closed’ in WordPress (Beginner’s Guide)

Category Image 091

Are you seeing the ‘Comments are closed’ message on your WordPress posts?

This message is displayed when comments have been disabled on a post. However, some users report seeing the message unexpectedly.

In this article, we’ll show you how to fix ‘Comments are closed’ in WordPress.

How to Fix 'Comments Are Closed' in WordPress (Beginner's Guide)

What Is the ‘Comments Are Closed’ in WordPress Error?

The comment area of your WordPress blog allows your website visitors to give feedback, ask questions, offer their own point of view on the topic, and respond to other comments.

Comments are disabled on all WordPress pages by default, and you won’t see the ‘Comments are Closed’ message on pages. However, you can still follow the steps below to open comments on your pages as well as posts.

For blog posts, you can disable comments on specific posts or on your entire WordPress website. For example, you may wish to disable comments on an announcement post.

When you disable comments on a post that has at least one comment, you will see the message ‘Comments are closed.’ This explains to your visitors that even though there are comments on the post, no further comments can be left.

The 'Comments are closed' Message

If you disable comments on a post that has no comments, then you won’t see the ‘Comments are closed’ message. WordPress will simply not display the comment form.

Perhaps you’re seeing the ‘Comments are closed’ message on your website unexpectedly. While WordPress is easy to use, some error messages can be hard to troubleshoot for beginners. That’s why we put together a list of the 50 most common WordPress errors and how to fix them.

This message is most likely being shown because of a WordPress setting that’s not configured correctly. That’s because WordPress has comments settings in multiple areas, which can make it hard for beginners to find the right settings to fix the problem.

In this post, we’ll walk you through all the settings you should check in order to reopen the comments on your blog posts.

With that being said, let’s look at how to fix ‘Comments are closed’ in WordPress.

Enable Comments on Future Posts

Comments are often closed on a WordPress site because at some time in the past a setting was checked was that disables comments on new posts by default.

You can check this setting by navigating to Settings » Discussion. Here you’ll find a set of checkboxes that control how comments are handled on new posts.

Enable Comments for Future Posts from Settings » Discussion

The first setting to look at is ‘Allow people to post comments on new articles’. This box should be checked so that the default setting for future posts is to allow comments.

Next, look at ‘Automatically close comments on articles older than XX days’. This setting is useful if you don’t want users to be able to comment on older posts. However, if you want to allow comments on all posts, then you should make sure this box is unchecked.

Once you’re happy with the discussion settings, make sure you click the ‘Save Changes’ button at the bottom of the screen to store the settings.

This will make sure comments are open on all new posts you create. But it will not enable them on posts that have already been created.

That’s what we’ll do in the next step.

Enable Comments on a Specific Post

This method will show you how to enable comments on existing posts one at a time. However, if you wish to enable comments on many posts, then you should follow the ‘Enable Comments in Bulk’ method that we cover below.

If you use the block editor on your WordPress site, then you need to scroll down the settings pane on the right of the screen until you come to the Discussion panel.

Now you should click on ‘Discussion’ to expand the options, and then make sure the ‘Allow comments’ box is checked.

Allow Comments on a Post or Page

Once you click the Update button at the top of the screen to save the setting, comments will be enabled for this post.

You should repeat these steps to enable comments on other blog posts. You can also follow the same process to enable comments on WordPress pages.

How to Display the Discussions Panel if It Is Hidden

While the Discussions panel is displayed by default, it may be hidden on your website. If you can’t find it, then you will need to click the Options icon at the top right of the screen. This icon looks like 3 vertical dots.

Post Preferences

You then need to click on ‘Preferences’ and navigate to the ‘Panels’ tab. Once there, you can toggle the ‘Discussions’ switch on so that the panel is displayed.

Toggle the Discussions Panel On

Enable Comments on a Specific Post (Classic Editor)

If you are using the classic editor, then the steps for enabling comments on a post are a little different. Here, the Discussion meta box is hidden by default. To display it, you will need to click on ‘Screen Options‘ at the top right of the screen.

Edit the Post and Click Screen Options

Next, you should check the Discussion box under ‘Screen elements’. After that, simply click ‘Screen Options’ again to return to your post.

Make Sure the Discussions Screen Element is Checked

You can now scroll down to the bottom of your post where you will find the Discussion meta box. You should make sure the ‘Allow comments’ box is checked.

Make Sure Allow Comments Is Checked

After you click the Update button to save the setting, comments will be enabled for this post.

Enable Comments on Posts in Bulk

If you need to enable comments on multiple posts, then you can update them in bulk. To do that, navigate to the Posts » All Posts page where you will find a list of all of your posts.

You need to select the posts that have comments disabled by clicking the checkbox next to each post.

After that, you should choose ‘Edit’ from the Bulk Actions dropdown box and then click the ‘Apply’ button. This will open the bulk edit screen.

Edit Multiple Posts at Once With Bulk Actions

Here you need to click the ‘Comments’ drop down menu and then select ‘Allow’.

Don’t forget to click the ‘Update’ button to change the setting for all selected posts.

Allow Comments for Multiple Posts at Once

How to Select All Posts At Once

If you want to enable comments for every post on your website at once, then following the steps above would take a lot of time if you have hundreds of blog posts on your site.

To do it faster, there are a few extra steps you should take. First, you will need to make sure that all posts are displayed on a single page.

You can see a count of all the posts on your website under the ‘Posts’ title at the top of the screen. If you have 20 posts or less, then they are already displayed on one page. If you have more than 20 posts, then you will have to increase the number of items per page.

To do that, you should click ‘Screen Options’ at the top of the page. Then, under Pagination, find the ‘Number of items per page’ setting. Here you will need to type a number larger than the total number of posts on your site.

Ensure All Your Posts Are Displayed on a Single Page

For example, if you have 65 posts on your website, then you could type the number 70.

After that, you need to click the ‘Apply’ button and all of your posts will be displayed on one page. You can now click ‘Screen Options again to hide the settings.

You can now select every post on your site by simply clicking the checkbox next to ‘Title’.

Click the Checkbox Next to Title to Select All Posts

To enable comments on all of these posts, you should click ‘Bulk Actions’ then ‘Edit’, and follow the steps we covered earlier in this section to change the Comments setting to ‘Allow’.

Note: We don’t recommend trying to update hundreds of blog posts at once if you have slow web hosting, since your site may time out or freeze up before completing all the updates.

Check for Incompatible Themes or Plugins

If you have tried all of the steps above and comments are still disabled on your site, then it may be because of an incompatibility with your theme or one of your plugins.

Sometimes poorly coded WordPress themes may wrongly display the ‘Comments are closed’ message even when comments are open.

To check if your theme is the problem, you should navigate to Appearance » Themes and temporarily activate some other theme.

Enable a Different Theme to See if the Issue Is Resolved

If the ‘Comments are closed’ message is now fixed, then your theme is the problem. You can ask the theme developer to fix the issue. For more details, see our guide on how to properly ask for WordPress support and get it.

Alternatively, if you’re an advanced user, then you can try to fix the issue yourself. You need to refer to our guide on how to disable comments in WordPress, and then follow the instructions under ‘Remove “Comments Are Closed” in WordPress’.

If you think a plugin may be causing the issue, then you can head over to Plugins » Installed Plugins and make sure you haven’t installed a plugin designed to disable comments, such as Disable Comments. If you have, then simply disable that plugin and test to see if comments are now working.

If comments are still closed, then you need to test for incompatible plugins. You’ll need to temporarily deactivate one plugin at a time by clicking its ‘Deactivate’ link.

Deactivate Plugins One at a Time to See if the Issue Is Resolved

Now test to see if comments are enabled on your site. If they are still not working, then this plugin is not the problem. Simply click its ‘Enable’ link and move on to the next plugin.

We hope this tutorial helped you learn how to fix ‘Comments are closed’ in WordPress. You may also want to learn how to increase your blog traffic, or check out our list of the best social media 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 How to Fix ‘Comments Are Closed’ in WordPress (Beginner’s Guide) first appeared on WPBeginner.

How to Easily Optimize WordPress CSS Delivery (2 Methods)

Category Image 052

Would you like to optimize your WordPress CSS delivery?

CSS files control the visual formatting and style of your WordPress website. But if your CSS code isn’t delivered in an optimal way, then it could be slowing down your website.

In this article, we’ll show you two easy methods to optimize your WordPress CSS delivery.

How to Easily Optimize CSS Delivery in WordPress

How WordPress CSS Delivery Affects WordPress Performance

CSS files are used to define the visual appearance of your WordPress site. Your WordPress theme contains a CSS stylesheet file, and some of your plugins may also use CSS stylesheets.

CSS is necessary for modern websites, but it’s possible for CSS files to slow down your site’s speed and performance depending on how they’re set up.

Even a small delay in site speed creates a bad user experience and may affect your search rankings and conversions, resulting in less traffic and sales.

StrangeLoop study

One way that CSS files can slow your website is if they need to be loaded before the page can be displayed. That means your visitors will see a blank page until the CSS file has loaded. This is known as render-blocking CSS.

Another common reason CSS files can slow your website is when they contain more code than is needed to display the visible part of the current page. That extra code means that they will take longer to load.

The good news is, you can improve your WordPress site’s performance by optimizing the way the CSS code is delivered.

That’s done by identifying the minimum CSS code needed to display the first part of the current web page. This is known as critical CSS.

This critical code is then added inline to the page’s HTML, instead of in separate stylesheets, so that the code can be rendered without needing to load the CSS file first.

The rest of the CSS can then be loaded after your visitors can see the contents of the page. This is known as ‘deferred loading’.

In this tutorial, we’ll show you two methods to optimize WordPress CSS delivery, and you can choose the one that works best for you.

Method 1: Optimizing WordPress CSS Delivery with WP Rocket

WP Rocket is the best WordPress caching plugin in the market. It offers the simplest way to optimize your WordPress CSS delivery. In fact, it’s as easy as checking a box.

WP Rocket is a premium plugin, but the best part is that all features are included in their lowest plan.

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

Once activated, you need to navigate to the Settings » WP Rocket page and switch to the ‘File Optimization’ tab.

Switch to the File Optimization Tab

Next, you need to scroll down to the CSS files section. Once there, you need to check the box next to the ‘Optimize CSS delivery’ option.

Check Optimize CSS Delivery

This feature will intelligently identify the critical CSS needed to format the part of the web page your visitors see first. Your pages will load more quickly, and the rest of the CSS will be loaded after your visitors can see its contents.

All you need to do now is click the Save Changes button and wait for WP Rocket to generate the necessary CSS file for all your posts and pages.

It will also automatically clear the cache for your website, so that your visitors will see the new optimized version of your site instead of the any unoptimized versions stored in cache.

There are plenty of other ways that WP Rocket can help you improve your website’s performance. To learn more, see our guide on how to properly install and setup WP Rocket in WordPress.

Method 2: Optimizing WordPress CSS Delivery with Autoptimize

Autoptimize is a free plugin designed to improve the delivery of your website’s CSS and JS files.

While Autoptimize is a free plugin, it doesn’t have as many features as WP Rocket and takes more time to set up.

For example, it’s not able to automatically identify critical CSS like WP Rocket can. Instead, Autoptimize requires the help of a premium third-party service which is an additional cost and requires extra time to configure.

However, it could be a good option if you’re on a tight budget and don’t need all the other features of WP Rocket to speed up your site.

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

Upon activation, you need to visit the Settings » Autoptimize page to configure the plugin settings. Once there, you need to scroll down to the CSS Options section and check the Optimize CSS Code box at the top.

Scroll Down to CSS Options

Once you do that you need to make sure that ‘Aggregate CSS-files’ option is unchecked and then check ‘Eliminate render-blocking CSS’.

You can now click on the ‘Save Changes and Empty Cache’ button to store your settings.

But the plugin will not work properly until you sign up for a Critical CSS account. This is a premium subscription service that will provide Autoptimize the critical CSS code it needs to optimize your WordPress CSS delivery.

To do that, navigate to the Critical CSS tab in Autoptimize’s settings. Here you’ll find the information you need to sign up with Critical CSS. You can get started by clicking the sign up link in the third paragraph.

Sign Up for a Critical CSS Account

Once you’ve received your Critical CSS API key, scroll down to the API Key section so you can paste it into the ‘Your API key’ text box. After that, make sure you click the Save Changes button.

Paste Your Critical CSS API Key

Autoptimize now has all of the information it needs to add the critical CSS inline and defer loading the stylesheets until after the page has been rendered. As a result, your website will load more quickly.

We hope this tutorial helped you learn how to optimize WordPress CSS delivery.

You may also want to see our ultimate guide on how much it really costs to build a WordPress website, and our comparison of the best managed WordPress hosting companies.

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 Easily Optimize WordPress CSS Delivery (2 Methods) appeared first on WPBeginner.

Overlay Fact Sheet

Category Image 052

I would hope all our web designer/developer spidey senses trigger when the solution to an accessibility problem isn’t “fix the issue” but rather “add extra stuff to the page.” This Overlay Fact Sheet website explains that. An “Overlay” is one of those “add extra stuff to the page” things, ostensibly for improving accessibility. Except, even though marketing may suggest they are a silver bullet to accessibility, they are… not.

The site does a much better job laying that out than I can, so go check it out. As I write, it’s signed by 352 people, mostly people who are accessibility professionals.

Direct Link to ArticlePermalink


The post Overlay Fact Sheet appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

Which Configuration Changes in SQL Server Require a Restart?

Category Image 091

SQL Server is a complex beast, with many configuration options that can range from recommended to completely avoided.

Since the release of SQL Server 2016, several options that were recommended post-install have been rolled into the default installation options and no longer need to be done, and similar changes were made with SQL Server 2017. Even so, there are configuration changes we data professionals need to make after installation, during maintenance windows, and sometimes even during operating hours, so here’s a handy list of changes that do and don’t require a restart of your operating system or SQL Server instance.

All in One SEO Plugin Turns on Automatic Updates without Notifying Users, Removes Functionality in Latest Release

Category Image 091

Buried in the changelog of a series of minor releases that dropped before the Christmas holiday, All in One SEO plugin users were given the surprise gift of automatic updates. After a seemingly endless run of releases (12 updates during a span of six weeks at the end of 2020), the plugin’s developers decided to change its auto update policy so that it defaults to “on.” The plugin is installed on more than 2 million WordPress sites.

Version 4.0.8, released December 21, 2020, flipped on automatic updates without notifying users of the change. Despite having auto updates turned off for the plugin, many users discovered the change when they were notified by email that their sites had been updated without permission.

Frustrated users took to the plugin’s support forums to report the issue and find out how it was possible.

“Multiple sites have updated to 4.0.11 without my permission and while all auto updates are disabled,” one user said. “I/we do not want to hear that ‘it shouldn’t happen’ and we are looking into.

“Your once reliable plugin has destroyed hundreds of pages of social meta data on multiple sites, broken layout (and this after I fixed the problems and told you last week, I will be disabling all updates).”

Others commented on the issue, citing problems with a previous major release as the source of many bugs that followed.

“The rollout of version 4, and auto-updating without any chance to backup first was a blunder by AIOSEO,” plugin user Derek Haines said. “It has cost me hours, days, and now weeks to fix the problems caused.”

The All in One SEO plugin team apologized for the inconvenience users experienced but said they could not reproduce it on their end. The plugin’s settings page has a toggle for auto updates but it is just a wrapper for WordPress’ auto updater.

“I just wanted to give you an update and let you know that we’ve decided to remove our own auto-update functionality all together since this issue seems to be happening on a limited amount of websites and we aren’t able to reproduce it on our end,” Arnaud Broes said.

The problem was also discussed in the Advanced WordPress Facebook group.

“All In One SEO Pack apparently turned auto updates on, and in a few cases I found sites where those updates failed,” Eric Karkovack reported. “I had no idea they were turned on and in one case a site was inaccessible.”

Karkovack noted that there was only a small mention in the changelog, despite the plugin liberally using the dashboard notification UI for sales.

William Earnhardt, WordPress core contributor and developer at Bluehost, offered some insight as someone who has worked on core as well as plugins installed on a massive scale.

“In my experience if you are weighing the two options, auto-updates prevent significantly more issues and support requests than they create,” Earnhardt said. “So I’m strongly in the camp of enabling them by default, with a mechanism for preventing or disabling for those who prefer (core makes this possible with filters and now with per-plugin UI).

“I think when making these decisions, we as developers have to consider what is best for the broadest number of users and be realistic about the type of users we have. If a user is already not updating plugins regularly, it is unlikely they are going to have the awareness to flip a toggle to turn auto-updates on. So opt-in makes them mostly useless.”

Earnhardt agreed that notifying users of the change would have been a good idea, but admin notices are already “frequently abused and quite noisy.”

“It would likely be missed if not persistent, but really should only show after the update and then go away,” he said. “Is that enough when combined with a note in the changelog? Probably for most, but I’m sure some would disagree.”

As promised nine days ago, All in One SEO’s developers have now removed the functionality from the plugin in its first update of 2021, version 4.0.12 released today. It is noted in the changelog: “Fixed: Completely remove auto updates wrapper to let WordPress handle updates.”

Quick Tips for High Contrast Mode

Category Image 052

Sarah Higley has some CSS tricks up her sleeve for dealing with High Contrast Mode on Windows, which I learned is referred to as WHCM.

Here’s the first trick:

[…] if the default CSS outline property doesn’t give you the visual effect you want [in WHCM] for focus states, there’s a very simple fix. Instead of overriding default browser focus styles with outline: none, make it transparent instead: outline 3px solid transparent.

That will essentially do nothing outside of WHCM, but in WHCM, it will be a thick white border, which is a strong, good visual focus style.

Direct Link to ArticlePermalink

The post Quick Tips for High Contrast Mode appeared first on CSS-Tricks.

How to Restart a WordPress Site – Reset WordPress (The Fast Way)

Category Image 091

Recently, one of our readers asked us, “How do I restart my WordPress site?”.

This isn’t something that most users will need to do, but knowing how to reset WordPress can be very helpful in some situations.

In this tutorial, we’ll show you how to restart or reset your WordPress site, the fast way.

Restarting a WordPress site

Why Restart a WordPress Site?

Restarting or resetting WordPress is a process where you restore WordPress to the default settings. Think of it as a similar process to restoring your phone to the default “factory settings”.

It will delete all your apps and customizations, so you can start over fresh.

There are several situations where you might want to restart or reset a WordPress site:

1. You’re using a demo site on your own computer. If you’ve installed WordPress on localhost, then you might want to reset after you’ve built a site and moved it from localhost to a live server. If you’re a developer and constantly test themes & plugins on your local install, then it can help to reset it every quarter to start fresh.

2. You’ve been working on a new site and want to start over. Maybe you’ve been busy creating a blog or website, but you are not happy with the customizations. Instead of undoing everything, you can simply reset WordPress and quickly start over with a new design.

3. You’re going to rework a client’s website. If they want something very different from what’s already there, then you might need to reset WordPress on staging server to start from scratch.

4. You’re learning about WordPress, hands-on. Maybe you’ve had a go at developing your own plugins or themes, or you’ve been experimenting with a starter theme. You might want to start again with a fresh installation of WordPress.

How to Restart and Reset a WordPress Site

Restarting your WordPress site might sound difficult, but it’s really not.

We’re going to walk you through the entire reset process, step by step.

Before you begin, it’s important to create a full backup of your site using a WordPress backup plugin. This is important in case you want to restore your site from the backup after restarting it.

Restart Your WordPress Site with WP Reset

Now you’re ready to move on and restart your WordPress site. We’re going to use the free version of the WP Reset plugin for this.

First, you’ll need to install and activate the WP Reset plugin. For more details, see our instructions on how to install a WordPress plugin.

Once the plugin is activated, you need to go to the Tools » WP Reset in your WordPress dashboard and scroll down to the Site Reset section of the page.

To reset your site, you need to type the word ‘reset’ in the confirmation field before clicking the red ‘Reset Site’ button.

The button in WP Reset to restart your WordPress site

WP Reset will pop up a message asking you to confirm that you want to reset the site. Click ‘Reset WordPress’ to continue.

Confirm that you want to reset your website

You’ll see a ‘Resetting in progress’ message for a few seconds. Then, your site will be restarted.

Next, you’ll see the homepage of your WordPress dashboard with a success message at the top from WP Reset.

WPReset's message confirming that you've successfully reset your WordPress site

That’s it. You’ve restarted your WordPress site.

Optional WP Reset Functions When Restarting Your Site

The above method gives you everything you need in order to restart your site.

However, there are some other options in WP Reset that you might want to use too.

Taking a Snapshot of Your WordPress Site Before Restarting

You can use WP Reset to take a snapshot of your site. A snapshot is a restore point for your WordPress database. It lets you see what changes have been made since the snapshot was taken. You can use it to roll back changes if necessary.

Important: A snapshot is not a WordPress backup. You should still make backups to restore your website.

To create the snapshot, click on the Snapshots tab. Then, scroll down and click the Create Snapshot button:

Creating a snapshot of your WordPress site before restarting it

You’ll be prompted to enter a name or description for the snapshot. Type in whatever you want to use, then click the ‘Create snapshot’ button.

Name the snapshot you're creating

Deleting Themes and Plugins Using WP Reset

By default, WP Reset doesn’t delete theme and plugin files. It simply deactivates them. However, you can use it to delete these files too.

First, you’ll need to go to Tools » WP Reset and click the ‘Tools’ tab. Once there, simply click on the ‘Delete Themes’ or ‘Delete Plugins’ links to jump straight to those tools.

Click the link to delete themes and/or plugins

Once you click either link, you’ll be scrolled down the page to the right tool:

Click the button to delete all themes from your WordPress site (including the active one)

You can click the ‘Delete all themes’ or ‘Delete plugins’ button to delete them.

Important: WP Reset doesn’t backup your files in any way. Deleting your themes and plugins can’t be undone.

After you click the button, you’ll be prompted to confirm. Click the Delete button on the popup to continue.

WP Reset will bring up a warning before allowing you to delete all themes

You’ll then see a message telling you how many themes or plugins have been deleted.

If you delete all themes, then you’ll need to install and activate a theme manually. Your site won’t work without one. If you go to Appearance » Themes, then you’ll see a screen like this:

The empty themes page with no themes installed

Go ahead and click the ‘Add New’ button and choose or upload a theme of your choice. If you need help, check out how to install a WordPress theme.

Restoring Your Data After Restarting Your WordPress Site

After restarting your WordPress site, any posts and pages you had will be gone. Instead, you’ll see the default pages and the ‘Hello, world’ post:

The 'Hello World' default post

To restore your old data, you will need to reinstall and activate the backup plugin that you used to create your backup.

You can then follow its instructions to restore your site from the backup.

Viewing Your Restored Content

Once you’ve restored your site from backup, your content should be back on your site.

You’ll find all your posts under Posts » All Posts. They’ll have the correct time stamps, categories, tags, and comments.

Viewing the imported postsv

We hope this tutorial helped you learn how to reset a WordPress site the fast way. You might also like our ultimate guide to speeding up WordPress and our list of must have WordPress plugins for all sites.

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 Restart a WordPress Site – Reset WordPress (The Fast Way) appeared first on WPBeginner.

Molly Burke on the Power of Universal Design

Category Image 091

In a 2017 speech titled “Stop trying to fix disability,” YouTube and motivational speaker Molly Burke says, “I live in a world that wasn’t built for me, but what if it was?” Burke was born with a rare, genetic eye disease that caused her to go blind. In this short but moving 8 minute video, she contends that making the world accessible helps everyone. She introduces the concept of universal design to her audience in simple terms:

“Universal design [is] designing and building everything to be accessed, enjoyed, and understood to its fullest extent by everyone, regardless of their size, their age, their ability, or their perceived disability.”

Burke identified Apple as one company that exemplifies universal design.

“Every product they release, I could buy at a store, open up, and use on my own independently, with no extra cost and no assistance needed,” she said. “I ask you to imagine how liberating, how empowering it is to be shown by a company that they view you as belonging to their customers, when so many others tell you the exact opposite.”

In honor of Global Accessibility Awareness Day, I wanted to highlight this video that tells just one person’s story on the powerful impact of technology that is built with everyone in mind. Burke’s speech is a poignant reminder of how designers and builders can extend a sense of belonging to their customers by making their products accessible.