WordPress 5 Cookbook - Rakhitha Nimesh Ratnayake - E-Book

WordPress 5 Cookbook E-Book

Rakhitha Nimesh Ratnayake

0,0
32,36 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Explore built-in WordPress features and the power of advanced plugins and themes for building modern websites using exciting recipes




Key Features



  • Build custom features and extend built-in features in WordPress with custom coding and plugins


  • Get to grips with extending WordPress as an application framework


  • Manage non-functional aspects of your website such as security, performance, and maintenance



Book Description



WordPress has been the most popular content management system (CMS) for many years and is now powering over 30% of all websites globally. With the demand for WordPress development and skilled developers ever-increasing, now is the best time to learn WordPress inside out.






This book starts with simple recipes for configuring WordPress and managing basic platform features. You'll then move on to explore how to install and customize WordPress plugins, widgets, and themes. The next few chapters cover recipes for content and user-management-related topics such as customizing the content display, working with content types, using the new Gutenberg editor, and customizing editorial workflow for building advanced blogs. As you advance, you'll learn how to use WordPress as an application framework as well as a platform for building e-commerce sites. This WordPress book will also help you optimize your site to maximize visibility on search engines, add interactivity, and build a user community to make the site profitable. Finally, you'll learn how to maintain a WordPress site smoothly while taking precautions against possible security threats.






By the end of the book, you'll have the tools and skills required to build and maintain modern WordPress websites with the latest technologies and be able to find quick solutions to common WordPress problems.




What you will learn



  • Install and customize WordPress themes and plugins for building websites


  • Develop modern web designs without the need to write any code


  • Explore the new Gutenberg content editor introduced in WordPress 5 (Bebo)


  • Use the existing WordPress plugins to add custom features and monetize your website


  • Improve user interaction and accessibility for your website with simple tricks


  • Discover powerful techniques for maintaining and securing your websites


  • Extend built-in WordPress features for advanced website management



Who this book is for



This book is for beginners who want to build powerful modern websites with minimum coding knowledge and intermediate web developers who want to extend the basic features of WordPress to cater to advanced modern website technologies. Although prior experience with WordPress is not required, familiarity with basic PHP, HTML, and CSS is necessary to understand the concepts covered.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 714

Veröffentlichungsjahr: 2020

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



WordPress 5 Cookbook

 

 

 

 

 

 

 

Actionable solutions to common problems when building websites with WordPress

 

 

 

 

 

 

 

 

 

 

 

Rakhitha Nimesh Ratnayake

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

WordPress 5 Cookbook

Copyright © 2020 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

 

Commissioning Editor: Pavan RamchandaniAcquisition Editor: Ashitosh GuptaContent Development Editor: Aamir AhmedSenior Editor: Hayden EdwardsTechnical Editor: Jane DsouzaCopy Editor: Safis EditingProject Coordinator: Kinjal BariProofreader: Safis EditingIndexer: Rekha NairProduction Designer:Alishon Mendonsa

First published: March 2020

Production reference: 1200320

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-83898-650-6

www.packt.com

 

I would like to thank my loving wife, Dulari; my daughter, Hesara; my parents; and my wife's parents for the help and encouragement they provided while I was writing this book. 

-Rakhitha Nimesh Ratnayake

 

Packt.com

Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Fully searchable for easy access to vital information

Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the author

Rakhitha Nimesh Ratnayake is a freelance web developer, writer, and open source enthusiast. He has over 9 years of experience in developing WordPress applications and plugins. He develops premium WordPress plugins for individual clients and the CodeCanyon marketplace. User Profiles Made Easy and WP Private Content Pro are the most popular plugins developed by him. Building Impressive Presentations with impress.js was his first book, which was published by Packt Publishing. He is also the author of the first three editions of WordPress Web Application Development. In his spare time, he likes to read books and spend time with his family.

I would like to thank Packt Publishing, especially acquisition editor Ashitosh Gupta for inviting me to write this book, content development editor Aamir Ahmed for closely working with me to complete this book, senior editor Hayden Edwards and project manager Divij Kotian, all other Packt staff who contributed to this book, and the reviewer for providing honest feedback to improve this book. Finally, I would like to thank you for reading my book and being one of the most important people who helped me make this book a success.  

About the reviewer

Thomas P. McDunn is an automation engineer with experience in machine design, electronics, and software of all kinds. He set up TPM Technologies, Inc. for small businesses to explore emerging social media as a marketing tool. His Lept Like a Blog program featured a WordPress core feeding the other popular social media platforms. He has guided more than 100 clients in developing a blog for their business utilizing this program. He has promoted the use of WordPress as an easy way to gain a strong online presence. As his clients grew, so did the website functionality that they needed. He helped them push the WordPress engine to meet their needs. To help bloggers keep up momentum, he formed multiple blogging clubs. He has also lectured on social media marketing in various venues for small businesses.

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Preface

Now powering over 30% of all websites, WordPress has been the most popular content management system (CMS) for the past 7 years and shows no signs of slowing down. With the demand for WordPress development and developers increasing everyday, now is the best time to learn everything about WordPress.

This book starts with recipes for configuring WordPress and managing basic features. You'll then explore the main components of developing a website, such as the installation and customization of WordPress plugins, widgets, and themes. As you progress through the chapters, you'll cover content and user management topics such as customizing the content display, advanced content types, using a new Gutenberg editor, and building an advance blog with custom editorial workflow. You'll learn how to use WordPress as an application framework and build e-commerce websites. This WordPress book helps you to optimize your site to maximize visibility on search engines, add interactivity, and build a user community to make the site profitable. Finally, you'll learn how to maintain a WordPress site while taking precautions against possible security threats.

By the end of the book, you'll have developed the skills required to build and maintain modern WordPress websites with the latest technologies and will be equipped with quick solutions to common challenges in using WordPress.

Who this book is for

This book is for developers looking to build powerful modern websites with minimum coding knowledge and intermediate web developers who want to extend the basic features and functionalities of WordPress websites. Though prior experience with WordPress is not required, familiarity with basic PHP, HTML, and CSS is necessary to understand the recipes covered.

What this book covers

Chapter 1, Setting Up WordPress and Customizing Settings, begins by focusing on the basic setup and configuration options that are built into the default WordPress CMS. We will be going through basic setup procedures such as managing media files, discussions, privacy policies, and permalinks. Also, we will look at the process of setting up and using multisite environment features within WordPress.

Chapter 2, Customizing Theme Design and Layout, focuses on using standard theme features and creating custom features through child themes and custom templates. The standard theme features include customizer, menus, and built-in theme options.

Chapter 3, Using Plugins and Widgets, focuses on creating custom widgets and plugins while extending existing features using these components. You will learn about the importance of plugins and widgets, how they fit into WordPress, and how you can use them to build real-world requirements.

Chapter 4, Publishing Site Content with the Gutenberg Editor, will help learn how to create posts and pages with the features of the new Gutenberg editor and use quick methods to add content compared to the previous Visual editor. The goal of this chapter is to teach you how to get used to new block-based editing with Gutenberg.

Chapter 5, Managing Users and Permissions,focuses on extending default user management features through the actions and filters of WordPress, as well as building custom user-related features. The goal of this chapter is to build a custom user creation and management process with additional data and bringing user-related features to the frontend of the site.

Chapter 6, Setting Up a Blogging and Editorial Workflow, aims to simplify the content creation and publishing processes of advanced blogs, teach you how to build a custom workflow, and introduce features that you can use to attract more visitors to blog posts. We will start by understanding all aspects of the default post-creation process. Then, we will simplify the blogging process and make it effective in a team environment with frontend post publishing, custom post statuses, and discussions between editors.

Chapter 7, WordPress as an Application Framework, lets you adapt existing WordPress features into advanced applications by extending them through WordPress hooks. We will also be focusing on routing to support additional features without the use of WordPress features, as well as using the REST API to enable data for other services and applications.

Chapter 8, Improving Usability and Interactivity, focuses to reduce the complexity of using a site. We will be achieving this goal by showing you how to identify areas that can be simplified further and adapt existing plugins to simplify those areas.

Chapter 9, Building E-Commerce Sites with WooComerce, helps you build an online shop for any product within a few hours, adjust the default features, and start selling. We will be learning about the most essential parts of the shop's setup, managing various products and order types, and building custom layouts for the shop.

Chapter 10, Troubleshooting WordPress, helps you identify common issues in WordPress sites as an administrator and try to resolve them using basic fixes before seeking technical support. We will be configuring the website to easily track errors, applying necessary modifications to prevent issues, and apply simple solutions to a common set of problems. In the process, we will be looking at issues caused by caching, plugins, themes, and databases, as well as conflicts with WordPress core issues.

Chapter 11, Handling Performance and Maintenance, makes you aware of the common issues faced in site maintenance and performance while implementing the common steps to prevent them and improve performance. We will be using existing plugins to handle common maintenance tasks without using custom coding.

Chapter 12, Improving Site Security, helps you take precautions against commonly identified security threats and how to identify the next steps in combatting new types of possible threats. We will be achieving this goal by improving the security of WordPress and database user accounts as well as implementing additional layers to block unauthorized users from gaining access to user accounts.

Chapter 13, Promoting and Monetizing the Site, gets you to implement methods of bringing more visitors to a site and strategies for generating revenue. The first step will be to make the site rank well in search engines, as that's the best method for generating traffic in large proportions. We will be creating sitemaps, looking at pinging, and generating search engine-friendly content to achieve this goal. Then we will be using different techniques, such as social sharing, to gain maximum exposure through social media. Finally, we will be converting traffic into revenue by creating landing pages, using analytics, and creating advertisements.

To get the most out of this book

Basic knowledge of PHP, JavaScript, HTML, and CSS is required. You also need a computer, a browser, a code editor, and an internet connection with the following working environment:

An Apache web server

PHP version 7.3 or higher (most sections of the book work with PHP 5.6.20+)

WordPress version 5.3.2 or higher

MySQL version 5.6+, or MariaDB 10.0+ 

You will need WordPress installed on your computer. All code examples have been tested using WAMP Server 3.1.9. However, they should work with any operating system with the preceding requirements.

Software/hardware covered in the book

OS requirements

WordPress 5.3.2 

Any OS

MySQL 5.6 or greater, or MariaDB 10.0 or greater

Any OS

Apache web server

Any OS

PHP 5.6.20+ (7.3 is recommended)

Any OS

FileZilla Client 3.47+, or any file transfer client program

Any OS

phpMyAdmin 5.0.1+, or any database administration tool

Any OS

 

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

Support

tab.

Click on

Code Downloads

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/WordPress-5-Cookbook. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Support: Author provides a additional resources section for this book to get support on existing recipes, submit errors and additional recipes on topics not covered in the book. Please visit www.wpexpertdeveloper.com/wordpress_cookbook, for submitting your queries and viewing more video tutorials. 

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Table of Contents

Title Page

Copyright and Credits

WordPress 5 Cookbook

Dedication

About Packt

Why subscribe?

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Conventions used

Get in touch

Reviews

Setting Up WordPress and Customizing Settings

Technical requirements

Managing media files with the Media Library

Getting ready

How to do it...

How it works...

There's more...

Setting up the discussion process

Getting ready

How to do it...

How it works...

There's more...

Creating and managing a privacy policy

Getting ready

How to do it...

How it works...

Customizing default WordPress emails

Getting ready

How to do it...

How it works...

There's more...

Configuring the structure of permalinks

Getting ready

How to do it...

How it works...

There's more...

Setting up WordPress Multisite

Getting ready

How to do it...

How it works...

There's more...

Creating a new site in a multisite network

Getting ready

How to do it...

How it works...

Managing multisite themes and plugins

Getting ready

How to do it...

How it works...

There's more...

Cloning a site in a multisite installation

Getting ready

How to do it...

How it works...

There's more...

Customizing Theme Design and Layout

Technical requirements

Using the theme customizer

Getting ready

How to do it...

Site Identity tab

Colors tab

Menus tab

Widgets tab

Homepage Settings tab

How it works...

Working with Custom CSS in live preview

Getting ready

How to do it...

How it works...

Using a custom page as a home page

Getting ready 

How to do it... 

How it works...

There's more...

Creating a child theme

Getting ready

How to do it...

How it works...

There's more...

Styling navigation menus

Getting ready

How to do it...

How it works...

There's more...

Creating conditional navigation menus

Getting ready

How to do it...

How it works...

Adding a video header to the theme

Getting ready

How to do it...

How it works...

Using conditional tags to control content display 

Getting ready

How to do it...

Displaying conditional content on the archive and single posts

Displaying content for guests and members

Using multiple conditional tags

How it works...

Displaying conditional content on the archive and single posts

Displaying content for guests and members

Using multiple conditional tags

There's more...

Creating page templates from scratch

Getting ready

How to do it...

How it works...

Creating a custom posts list template

Getting ready

How to do it...

How it works...

There's more...

Creating a custom 404 error page 

Getting ready 

How to do it...

How it works...

There's more...

Using Plugins and Widgets

Technical requirements

Managing widgets in widget areas

Getting ready

How to do it...

Adding a Text widget to the footer area

Adding a Gallery widget to the footer area

How it works...

There's more...

Creating a simple widget from scratch

Getting ready

How to do it...

How it works...

Understanding the functionality of a form function

Understanding the functionality of the widget function

Understanding the functionality of the update function

Creating additional widget areas

Getting ready

How to do it...

How it works...

There's more...

Displaying conditional widgets with built-in tags

Getting ready

How to do it...

How it works...

There's more...

Displaying widgets inside of posts and pages

Getting ready

How to do it...

How it works...

Modifying plugin files with the built-in Plugin Editor

Getting ready

How to do it...

How it works...

There's more...

Working with custom PHP codes

Getting ready

How to do it...

How it works...

Manually deactivating plugins

Getting ready

How to do it...

How it works...

There's more...

Customizing WordPress plugins with actions and filters

Getting ready

How to do it...

How it works...

There's more...

Publishing Site Content with the Gutenberg Editor

Adding and removing Gutenberg blocks

Getting ready

How to do it...

How it works...

Using a Paragraph block inside the editor

Using a Gallery block inside the editor

Using the Visual and Code editors with the block editor

Getting ready

How to do it...

How it works...

Creating reusable Gutenberg blocks

Getting ready 

How to do it...

Creating a reusable block

Using reusable blocks

How it works...

There's more...

Editing reusable blocks from the Gutenberg editor

Converting a regular block into a reusable block

Using reusable blocks within other reusable blocks

Styling built-in content blocks

Getting ready

How to do it...

How it works...

Embedding content from external services

Getting ready 

How to do it...

How it works...

There's more...

Simplifying block editing with Gutenberg tools

Getting ready

How to do it...

Adding blocks before or after a block

Duplicating blocks

Customizing block arrangement

How it works...

Adding blocks before or after a block

Duplicating blocks

Customizing block arrangement

Adding a post grid with Gutenberg

Getting ready

How to do it...

How it works...

There's more...

Adding a contact form using Gutenberg

Getting ready

How to do it...

How it works...

Managing Users and Permissions

Technical requirements

Enabling new user registrations

Getting ready

How to do it...

How it works...

Managing user roles and permissions

Getting ready

How to do it...

Creating a new user role

Updating the capabilities of user roles

Creating a new capability

How it works...

Creating a new user role

Updating the capabilities of user roles

Creating a new capability

Assigning user roles to existing users

Getting ready

How to do it...

How it works...

Creating a custom role and setting up a default role

Getting ready

How to do it...

How it works...

Improving user profiles with additional fields

Getting ready

How to do it...

How it works...

Managing the visibility of the admin toolbar 

Getting ready

How to do it...

How it works...

There's more...

Adding custom features to the user list

Getting ready

How to do it...

How it works...

Displaying online users

Getting ready

How to do it...

How it works...

Adding email activation for new user accounts

Getting ready

How to do it...

How it works...

Sending the activation email

Blocking the login for pending activation

Activating the user from an email link

Switching users

Getting ready

How to do it...

How it works...

Displaying recently registered users

Getting ready

How to do it...

How it works...

Creating a frontend user list and search

Getting ready

How to do it...

How it works...

Setting up a Blogging and Editorial Workflow

Technical requirements

Publishing and scheduling blog posts

Getting ready

How to do it...

How it works...

Displaying author profiles in posts

Getting ready

How to do it...

How it works...

Enabling frontend post publishing

Getting ready

How to do it...

How it works...

Modifying a user list to show author publishing details

Getting ready

How to do it...

How it works...

Managing custom post statuses

Getting ready

How to do it...

How it works...

Setting up a discussion between authors and editors

Getting ready

How to do it...

How it works...

Splitting a single post into multiple parts

Getting ready

How it works...

How to do it...

Creating private posts for specific users

Getting ready

How to do it...

How it works...

Adding ratings to blog posts

Getting ready

How to do it...

How it works...

Podcasting with WordPress

Getting ready

How to do it...

How it works...

WordPress as an Application Framework

Technical requirements

Managing advanced data with custom post types

Getting ready

How to do it...

How it works...

Creating and managing advanced post fields

Getting ready

How to do it...

How it works...

Working with WordPress loop

Getting ready

How to do it...

How it works...

There's more...

Displaying advanced post fields

Getting ready

How to do it...

How it works...

There's more...

Restricting post/page content with shortcode

Getting ready

How to do it...

How it works...

Capturing data with dynamic forms

Getting ready

How to do it...

How it works...

Creating custom routes

Getting ready

How to do it...

How it works...

Storing custom data in existing tables

Getting ready

How to do it...

How it works...

There's more...

Creating and managing custom tables

Getting ready

How to do it...

How it works...

Using the REST API

Getting ready

How to do it...

How it works...

Improving Usability and Interactivity

Technical requirements

Creating a mobile-friendly site

Getting started

How to do it...

How it works...

Adding print, PDF, and email buttons to posts

Getting ready

How to do it...

How it works...

Customizing WordPress search

Getting ready

How to do it...

How it works...

There's more...

Searching specific categories and meta values

Limiting searching to a set of posts

Differentiate search results for multiple searches

Displaying a frontend login form

Getting ready

How to do it...

How it works...

There's more...

Optimizing images

Getting ready

How to do it...

How it works...

There's more...

Lazy loading posts with Ajax

Getting ready

How to do it...

How it works...

Highlighting the search term in the search results

Getting ready

How to do it...

How it works...

There's more...

Creating breadcrumbs for better navigation

Getting ready

How to do it...

How it works...

Adding an image gallery to pages

Getting ready

How to do it...

How it works...

Allowing testimonials on your site

Getting ready

How to do it...

How it works...

Integrating a forum into your site

Getting ready

How to do it...

How it works...

Building E-Commerce Sites with WooComerce

Technical requirements

Setting up an e-commerce site with WooCommerce

Getting ready

How to do it...

Configuring product settings

Configuring shipping settings

Configuring payment settings

Configuring Accounts and Privacy settings

Configuring Advanced settings

How it works...

General settings

Product settings

Shipping settings

Payment settings

Account and Privacy settings

Advanced settings

Creating and displaying a product

Getting ready

How to do it...

How it works...

Creating orders and managing order statuses

Getting ready

How to do it...

How it works...

Displaying WooCommerce products on custom pages

Getting ready

How to do it...

Displaying WooCommerce products with shortcodes

Displaying WooCommerce products with Gutenberg blocks

How it works...

Using shortcodes for products

Using Gutenberg blocks for products

Building custom product types

Getting ready

How to do it...

How it works...

There's more...

Selling memberships with membership products

Selling event tickets

Customizing the shop template

Getting ready

How to do it...

How it works...

Customizing the product page template

Getting ready

How to do it...

How it works...

Adding custom content after the Add to Cart button

Adding custom content between existing items

Troubleshooting WordPress

Technical requirements 

Configuring error logs and displaying errors

Getting ready

How to do it...

How it works...

There's more...

Fixing the WSoD

Getting ready

How to do it...

How it works...

Resolving conflicts in maintenance mode

Getting ready

How to do it...

How it works...

Manually resetting user passwords

Getting ready

How to do it...

How it works...

Fixing slow WordPress sites

Getting ready

How to do it...

Using caching to improve loading time

Using minification to improve loading time

Limiting plugins and queries to improve loading time

How it works...

Fixing issues with cached content

Getting ready

How to do it...

How it works...

Resolving WordPress core database issues

Getting ready

How to do it...

How it works...

Resolving JavaScript errors

Getting ready

How to do it...

A WordPress core script file is causing the issue

A script file from a plugin is causing the issue

How it works...

Fixing issues caused by theme/plugin upgrades

Getting ready

How to do it...

How it works...

Handling Performance and Maintenance

Technical requirements

Limiting post revisions

Getting ready

How to do it...

How it works...

Creating and scheduling database backups

Getting ready

How to do it...

How it works...

Restoring database backups

Getting ready

How to do it...

How it works...

Tracking site activities

Getting ready

How to do it...

How it works...

Identifying and resolving broken site links

Getting ready

How to do it...

How it works...

Backing up site files and uploads

Getting ready

How to do it...

How it works...

Cleaning unused data from the database

Getting ready

How to do it...

How it works...

There's more...

Setting up maintenance mode

Getting ready

How to do it...

How it works...

Migrating WordPress sites to new servers

Getting ready

How to do it...

How it works...

There's more...

Migrating from Drupal to WordPress

Getting ready

How to do it...

How it works...

Migrating from Joomla to WordPress

Getting ready

How to do it...

How it works...

Improving Site Security

Technical requirements

Upgrading the WordPress version

Getting ready

How to do it...

How it works...

Disabling plugin and theme file editing

Getting ready

How to do it...

How it works...

There's more...

Protecting backend logins by limiting login attempts

Getting ready

How to do it...

How it works...

Creating automatically expiring user passwords

Getting ready

How to do it...

How it works...

Securing user accounts

Getting ready

How to do it...

Changing the admin username

Displaying a custom login error message

Adding strong passwords to users

How it works...

Changing the admin username

Displaying a custom login error message

Adding strong passwords to users

Forcing logout for all users

Getting ready

How to do it...

How it works...

Protecting user accounts with two-factor authentication

Getting ready

How to do it...

How it works...

Protecting private sites with a global password

Getting ready

How to do it...

How it works...

Limiting site access to certain IPs

Getting ready

How to do it...

How it works...

Securing database user accounts

Getting started

How to do it...

How it works...

Testing site security issues

Getting ready

How to do it...

How it works...

There's more...

Promoting and Monetizing the Site

Technical requirements

Enabling visibility for search engines

Getting ready

How to do it...

How it works...

Optimizing pings to third-party services

Getting ready

How to do it...

How it works...

Creating an XML sitemap

Getting ready

How to do it...

How it works...

Optimizing content for search engines

Getting ready

How to do it...

How it works...

Adding social sharing buttons to posts

Getting ready

How to do it...

How it works...

Building an audience with newsletters

Getting ready

How to do it...

How it works...

Building a landing page with a page builder

Getting ready

How to do it...

How it works...

Integrating Google Analytics

Getting ready

How to do it...

How it works...

Monetizing the site with custom ad spots

Getting ready

How to do it...

How it works...

There's more...

Integrating Google AdSense for displaying ads

Getting ready

How to do it...

How it works...

Appendix

Configuring and setting up WordPress

Understanding the WordPress database

Working with the WordPress database

Viewing data of database tables

Viewing data of selected records

Understanding the WordPress directory structure

Additional resources

Other Books You May Enjoy

Leave a review - let other readers know what you think

Setting Up WordPress and Customizing Settings

In this chapter, we will begin by focusing on the basic setup and configuration options that are built into the default WordPress Content Management System (CMS). We will be going through basic setups such as managing media files, discussions, privacy policies, and permalinks. Also, we will look at the process of setting up and using multisite environment features within WordPress. The goal of this chapter is to teach you how to prepare basic WordPress tools so that you can manage advanced tasks in the upcoming chapters.

In this chapter, we will learn about the following recipes:

Managing media files with the Media Library

Setting up the discussion process

Creating and managing a privacy policy

Customizing default WordPress emails

Configuring a Permalinks structure

Setting up WordPress Multisite

Creating a new site on a multisite network

Managing multisite themes and plugins

Cloning a site in a multisite installation

Technical requirements

Code files are not required for this chapter.

Managing media files with the Media Library

The built-in Media Library is where you store all your images, videos, audio, and other files. We can directly add media to the library for later use or we can directly add them to posts. Existing features include the ability to edit and search media files, which makes life easier for the administrator.

In this recipe, we are going to use the Media Library to upload and organize files while executing the built-in features on media files.

Getting ready

You need to have an existing WordPress installation to work with these recipes. The necessary features are available on the WordPress dashboard.

How to do it...

To start adding media files, follow these steps:

Log in to the WordPress

Dashboard

as an administrator.

Click on the

Media

menu.

You will get a screen similar to the following Media Library screen. The list will be empty since you don't get any media files with a default WordPress installation:

Click on the

Add New

button to upload new files. You will get a screen similar to the following:

Drag some image files from your computer and drop them into the 

Drop files here

area. Alternatively, you can select them using the

Select Files

button.

Once you've selected some files, WordPress will automatically upload them and list them at the bottom of the screen, as shown in the following screenshot:

Now, visit the

Media | Library

section and click the

List

icon to see the uploaded files appear at the top of the list as shown in the following screenshot.

You can continue this process to add any number of allowed files to the

Media Library

.

Now, we can take a look at the common operations inside the Media Library.

To edit a file, we have to go through the following steps:

Hover the mouse over the top of a file from the list. Here, you will see the

Edit

link, as shown in the following screenshot:

Click on the

Edit

link. This will open the following screen so that you can edit files:

You can add a title, alternative text, a caption, and a description. After you've done this, click the 

Update

button to save the details.

When editing an image, you will get another button called Edit Image. Clicking that will take you to the image editing screen, as shown in the following screenshot. You can use this screen to crop, scale, or rotate an image and save it to the library:

To Crop, Scale, and Rotate an image, we have to go through the following steps:

Go to the 

Scale Image

section and reduce the width and height according to your needs.

Click the 

Scale

button to resize the image.

Go to the image under the 

crop

buttons on the left and click on it.

Then, drag it to select the area for cropping, as shown in the following screenshot:

Click the 

Crop

button to crop the image.

Click the 

Rotate

buttons alongside the 

Crop

button to rotate the images either left or right.

To delete a file, we have to go through the following steps:

Hover the mouse over the top of a file from the list. By doing this, you will see the

Delete Permanently

link.

Click on the

Delete Permanently

link to delete a file.

Click

OK

in the popup alert box to delete the file from the library.

To attach a file to a post, we have to go through the following steps:

Select a file from the list and click the

Attach

button in the 

Uploaded to

column. You will see a screen similar to the following:

Select the post you want and click the

attach

button to attach the file to a specific post. You will see an output that looks similar to the following:

You can also view and search for files from the Media Library. The files in the Media Library can be used when creating and editing posts and pages.

How it works...

Once a new file has been uploaded from the media uploader, it will be saved in the wp-content/uploads folder of your WordPress site with a unique file name. Inside the uploads folder, there will be several folders for each year and month. If we upload the file in January 2020, the path to the file will be wp-content/uploads/2020/01. If we upload an image file, WordPress will automatically create several images with different sizes called thumbnail, medium, and large. Then, WordPress will use the appropriate size in different places such as an archive page, single post, and so on. The original image will be also stored along with these resized versions.  

Also, details about these files will be stored in the wp_posts table as a special post type called attachment. The following screenshot shows how the attachments are stored in the database using the phpMyAdmin tool:

If you are not familiar with working with a database, use the Appendix to understand the process of using a database management tool to view this data.

The Media Library lists the available files by executing database queries on the wp_posts table.  

Then, we looked at editing files. The normal editing process allows you to add a caption and description for the file. However, WordPress provides additional editing features for images. We used the scaling, cropping, and rotating features for images. Once these features have been applied and saved, WordPress will create another set of images with different sizes inside the same folder path. The Media Library will only display the latest modified version of the image. Other versions before the last edit will be discarded. 

Next, we looked at the process of deleting files. Once we click the Delete Permanently link for a media file, it will be removed from the database and the file will be deleted from the path inside the wp-content/uploads folder. If we are deleting an image, it will remove all versions of the image, including the images that were created with each edit. 

Finally, we looked at the process of attaching a file to a post. Both posts and attachments are stored in the wp_posts table in WordPress. Once a media file has been attached to a post, the media file record in the wp_posts table will be updated to include the ID of the post as a parent of the media file. So, WordPress will use the parent ID to identify whether a file is attached to a post/page. If we detach the file, the parent ID will be set to 0 to remove the relationship. 

There's more...

In the previous section, we looked at the process of uploading files directly to the Media Library. We can also upload files directly to posts/pages. These files will also be added automatically to the Media Library. Let's see how we can add a file to a post and get it in the Media Library:

Click on the

Posts

menu.

Click the

Add New

button to create a new post.

Click the plus (

+

) sign on the following screen to add a block in the post-editing screen:

Type

File

 to find the file block.

Click

File block

to upload a file.

Click the 

Upload

button and select a file from your computer to upload it.

The file will be uploaded and added to the post. Also, the file will be listed in the Media Library as being attached to the newly created post.

Setting up the discussion process

In modern sites, rather than provide static information for reading we want people to interact with the site. Enabling discussions in posts and pages is the first and simplest step to begin user interaction on sites. WordPress provides a separate section that you can use to manage discussion-related settings.

In this recipe, we are going to look at the available settings and how to configure them properly to optimize the discussion process.

Getting ready

Twenty Twenty theme should be activated before starting this recipe. WordPress 5.3.2 and higher versions have the Twenty Twenty theme activated by default. If you have changed the theme, use the following steps to activate it.

Login to

Dashboard

as an administrator

Click

Appearance

menu item on the left menu

Click

Activate

button of Twenty Twenty theme

Now, you are ready to start this recipe.

How to do it...

The process of configuring discussion settings is site-specific. Follow these steps to identify and configure the most common discussion settings:

Log in to the WordPress

Dashboard

as an administrator.

Click on the

Settings

menu.

Click on the

Discussion

option.

You will get a screen similar to the following, which shows all the available settings related to discussion:

Find the following settings and keep or change the values based on your preferences. These settings will be explained in the 

How it works...

section:

Users must be registered and logged in to comment

Comment author must fill out name and email

Automatically close comments on articles older than [x] days  

Email me whenever anyone posts a comment

Email me whenever a comment is held for moderation

Before a comment appears Comment must be manually approved

Before a comment appears Comment author must have a previously approved comment

Click the 

Save Changes

button to apply the settings.

Now, you can view a post from the frontend of your site to see the comments section, as follows:

The commenting section will be displayed based on the settings you selected in the previous steps. Now, the user can use this form to submit comments. You can view the submitted comments by logging in to the Dashboard as an administrator and clicking the Comments menu item on the left menu.

How it works...

Once the settings have been saved, WordPress will change the built-in comments section so that it matches your preferences. Each of the available settings plays a different role in handling discussions. We have only selected settings that are the most important for any site. Let's take a look at how these settings work:

Users must be registered and logged in to comment

(

Signup has been disabled. Only members of this site can comment.

): By default, any user visiting the site will be able to comment by providing their name and email. However, in certain scenarios, you may want to restrict this to members only. Avoiding a lot of spam comments and building a member-specific private site are two such scenarios where this is a good idea. Once this setting has been enabled, users won't be able to comment unless they have registered and logged in to the account.

Comment author must fill out name and email

:

 

This is enabled by default, and makes the name and email fields compulsory in the comment form. Enabling this setting allows you to identify the users rather than having a lot of unnecessary comments from random people. Disabling this setting could increase spam comments. Hence, you should be careful when changing this setting.

Automatically close comments on articles older than x days

:

T

his setting specifies whether to close comments after a certain number of days. This is disabled by default. We can enable this setting and define the period in most sites to avoid spending time moderating comments on old posts. Once enabled, the comment form will be removed after specified days and will only allow visitors to view the content.

Email me whenever anyone posts a comment

:

T

his setting is enabled by default and the site admin will get an email for each comment. This could be unnecessary overhead in many simple sites where you don't need immediate comment approvals. Therefore, you can disable the notification if real-time comment approval is not important in your context.

Email me whenever a comment is held for moderation

:

T

his is similar to the previous setting, but this will notify you when you need to approve/decline a comment. It's better to disable it unless timely comment approval is very important in your context.

Before a comment appears Comment must be manually approved

:

T

his is disabled by default and all comments are approved automatically. Once you start getting a lot of spam or unnecessary comments on your site, you can enable this option. Once enabled, the comment will be only visible to the person who commented and admins, until it's approved to be displayed to the public.

Before a comment appears Comment author must have a previously approved comment

: This setting is similar and enabled by default. An admin has to approve the first comment from a specific user. After that, the user will be able to post more comments without requiring moderation.

There is no fixed setup for these settings. Due to this, you should check the requirements of the site and adjust them accordingly to provide the best discussion process.

There's more...

In this recipe, we looked at the first part of the discussion settings screen. There is also another important section on this screen called Comment blacklist. Once a site is open for user comments, anyone can come and add any content they like. Sometimes, it might not be related to your post and sometimes, it could be just spam content promoting their own products or services. In order to limit these unnecessary comments, we can use the Comment Blacklist setting to add the words we want to block. Once WordPress detects comments with one of these words, it will trash the comment. This is useful to avoid spam comments and reduce the time spent moderating these comments.

In this recipe, we looked at the discussion-related settings and applied them globally to all parts of the site. However, we have the ability to enable or disable discussion on specific posts by using the Settings section within each post. The following screenshot shows the discussion settings inside the post:

From here, we are allowed to enable/disable comments, pingbacks, and trackbacks for individual posts. However, other settings can be applied globally to each and every post.

Creating and managing a privacy policy

Privacy is one of the main concerns for users when using a new website or service. Modern websites use personal data as well as a user's behavior to improve their features and user-friendliness. The privacy policy on a website defines what kind of data is collected from users and how the data will be used. With the introduction of the GDPR regulation by the European Union, privacy policies have become a mandatory requirement for most sites.

The latest versions of WordPress contains a built-in privacy policy page where admins can customize the content according to their preferences and display it on the site.

In this recipe, we are going to look at the default privacy policy feature and its configuration.

Getting ready

Special preparation is not required for this recipe. The necessary features are available on the WordPress dashboard.

How to do it...

Creating a privacy policyis as simple as configuring and saving a single setting in the Dashboard. Follow these steps to create a Privacy Policy page and identify different ways of creating privacy policy content:

Log in to the WordPress

Dashboard

as an administrator.

Click on the

Settings

menu.

Click on the

Privacy

option.

The

Privacy

 

Setting

s

screen can be seen in the following screenshot. Here, we have to configure the

Change your

Privacy Policy page

setting. By default, a page called

Privacy Policy

will be selected:

Select the default page or select one of the existing pages and click the 

Use This Page

button to use it as the privacy policy. Also, you have the option of creating a new page and assigning it as a privacy policy page by using the 

Create New Page

button.

Click the 

Edit

link to edit the content of the

privacy policy page

. You will get a screen similar to the following:

Modify the content of the default privacy policy so that it suits the requirements of your site. Then, click the 

Publish 

button to save changes.

Now, you can view the privacy policy on the frontend by clicking the View link of the Privacy Policy page. You will see the default Privacy Policy content or customized content based on the options you chose previously.

How it works...

We have three ways of assigning the Privacy Policy page in WordPress, as follows:

WordPress provides a built-in page called Privacy Policy with the default content. The page is saved as a draft. Once we select the default page and click the 

Use This Page

button, the built-in page will be used as the Privacy Policy page. You will have to

Publish

the page as it's in draft status by default.

We have the option to choose a custom page and click the

Use This Page

button. In this case, you will have to write the entire privacy policy from scratch on a new page before assigning it to this setting. The default privacy policy content of WordPress will not be used.

We have the ability to create a privacy policy on a new page. In this case, you have to click the

Create New Page

button. Once clicked, WordPress will publish a new page with default privacy policy content. You can adjust the content and update the page. Now, the new page will be used as the privacy policy and the default privacy policy page will still exist as a draft that includes the original privacy policy content.

Once the privacy policy has been added using one of these methods, we can let visitors view the Privacy Policy as a normal WordPress page.

Customizing default WordPress emails

Email notifications in a site help users and administrators keep track of the site's activities and urges them to take action. WordPress provides a set of built-in email templates for major actions. More often than not, we will need to customize the content of these default email templates based on the type of the site and its requirements. As of version 5.3.2, WordPress doesn't offer features for customizing email content from the dashboard. Using the built-in filter hooks is the only way to customize the content. So, non-technical users may face difficulties when changing these emails.

In this recipe, we are going to use the Better Notifications for WordPress plugin to customize the default emails. We will learn how this plugin can be used to introduce and customize emails for actions not provided by WordPress.

Getting ready

You have to install the Better Notifications for WordPress plugin to execute this recipe. To do this, follow these steps:

Click

Plugins

|

Add New

.

Search for 

Better Notifications for WordPress

in the

Search plugins

field.

Once the plugin appears, click the

Install Now

button.

Finally, click the 

Activate

button to activate the plugin.

How to do it...

Follow these steps to create a new notification type and customize the content of WordPress emails:

Log in to the WordPress

Dashboard

as an administrator.

Click the 

Notifications

menu that's generated by the plugin.

Now, you will get a list of notifications that have been created by the plugin, as shown in the following screenshot. At this stage, it will be empty as we haven't created any notifications:

Click the 

Add New

menu item to create a notification and customize the content of WordPress emails. You will get a screen similar to the following:

Select the 

New User Registration – For User

option under the 

Notification For

setting.

Fill in the email formatting, subject, and content for the email. You can use the

Insert Default Content

button to view the default template for this email and then modify it based on your requirements.

Click the 

Save

button to save the new template for user registration emails.

You can follow the same process for other email templates. Once a new user registers through the site, an email that includes customized content will be sent to the user's email.

How it works...

The Better Notifications for WordPress plugin lists all the available email notifications, including default emails and custom emails, that are created by using existing WordPress hooks. The options that are listed in the Admin and Transactional sections are available by default in WordPress.

Let's take a look at the available settings:

Email Formatting

: This setting is used to define whether the email will be in plain text or HTML format.

Subject

: This will be the subject of the email that's sent by WordPress.

Message Body

: This will be the content of the email that's sent by WordPress.

Once WordPress tries to send an email, this plugin looks in its notification table for an appropriate notification for the scenario. If a matching notification is found, the plugin will override the default WordPress email with all the settings. So, the user, in this case, will get a custom email that's been configured by the plugin.

There's more...

In the previous section, we only looked at the settings that are available for all the email templates. However, there are more settings that work only with certain email templates, such as admin emails and custom emails.

Let's look at additional available settings for specific templates:

Additional Email Fields

: Once this setting is enabled, you will get a new set of settings to define, including the name, email, reply to email, and CC and BCC emails. By default, you will have to use WordPress filter hooks to define these values, which is difficult for a non-technical administrator. With this plugin, you can input all these values to make the email more user-friendly and send it to additional users.

Send To

: These settings are used to define specific user roles or users that will receive this email. So, we can conditionally set which users will get the notification.

Except For

: This setting implements the opposite of the previous setting, where we can define which roles or users will not receive this email. Once this setting is used, every user except those defined here will receive the notification.

You can configure multiple email notifications for the same email type with different conditions and send different emails to different types of users.

Configuring the structure of permalinks

A permalink refers to the permanent unique link to a certain post, page, or custom screen on your WordPress site. Most existing search engines give high priority to the words in the permalink when ranking a certain URL in search results. So, it's important to set up permalinks properly to make them user-friendly as well as search engine-friendly. WordPress provides in-built permalink structures and allows you to define your own custom structures.

In this recipe, we are going to look at the process of changing the default permalink structure and configuring a search engine-friendly permalink structure.