Wednesday, December 8, 2021

How to Add the First and Last CSS Class to WordPress Menu Items

Do you need to add custom styling to the first and last items of your WordPress navigation menu?

You could simply add a custom CSS class to the first and last menu items, but if the menu is rearranged, then those items will no longer be first and last.

In this article, we’ll show you how to add a .first and .last class that will style the first and last menu items even if the menu items are reordered.

How to Add the First & Last Class to WordPress Navigation Menu Items

Why Style the First and Last Navigation Items Differently?

In a past custom design project, we needed to add some custom styling to the navigation menu items of a WordPress website. This design in particular required different styling for the first menu item and the last menu item.

Now we could easily edit the menu and add a custom CSS class to the first and last menu item. But because we were delivering the project to a client, our solution had to work even if they rearranged the order of the menus.

So we decided to do use filters instead.

In this tutorial, we’ll show you two ways to style the first and last items of your navigation menu. You can choose your preferred method from the list below:

Method 1: Adding First and Last Class Using a Filter

The first way to style your first and last navigation menu items differently is to add a filter to your theme.

You’ll need to add code to your theme’s functions.php file. If you haven’t done this before, then see our guide on how to copy and paste code in WordPress.

All you have to do is open your theme’s functions.php file then paste the following code snippet:

function wpb_first_and_last_menu_class($items) {
    $items[1]->classes[] = 'first';
    $items[count($items)]->classes[] = 'last';
    return $items;
}
add_filter('wp_nav_menu_objects', 'wpb_first_and_last_menu_class');

This creates .first and .last CSS classes for your first and last navigation menu items respectively. You can use those classes to style the menu items.

To learn how to do this in detail, refer to our guide on how to style WordPress navigation menus.

For this tutorial, we’ll add the following basic CSS formatting to our theme’s style.css stylesheet to simply bold the first and last menu items:

.first a {font-weight: bold;}

.last a {font-weight: bold;}

Here you can see screenshots before and after we added the code to our demo site.

Preview of First and Last Menu Items Styled Differently

Method 2: Styling First and Last Items Using CSS Selectors

A second way to style the first and last menu items differently is to use CSS selectors. This method is simpler, but it may not work with some older browsers, such as Internet Explorer.

To follow this method you’ll have to add code to your theme’s style sheet or the ‘Additional CSS’ section of the WordPress Theme Customizer.

If you haven’t done this before, then see our guide on how to easily add custom CSS to your WordPress site.

You should start by editing your theme’s style.css file, or by navigating to Appearance » Customize and clicking on ‘Additional CSS’.

After that, you need to paste the following code snippet and then save or publish your changes.

ul#yourmenuid > li:first-child { }
ul#yourmenuid > li:last-child { }

Note that you will need to replace ‘yourmenuid’ with the actual ID of the navigation menu. The selectors ‘first-child’ and ‘last-child’ select an element if it is the first and last child of its parent, which is the navigation menu.

For example, we used this code to bold the first and last navigation menu items on our demo site:

ul#primary-menu-list > li:first-child a {
    font-weight: bold;
}
ul#primary-menu-list > li:last-child a {
    font-weight: bold;
}
Using CSS Selectors to Style First and Last Menu Items Differently

We hope this tutorial helped you learn how to add the .first and .last class to WordPress navigation menus.

You may also want to learn how to fix 50 common WordPress errors, or check out our list of the best drag and drop page builders.

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 the First and Last CSS Class to WordPress Menu Items first appeared on WPBeginner.


December 08, 2021 at 04:00PM

Tuesday, December 7, 2021

How to Submit your WordPress Site to Google News

Do you want your WordPress site to show up in Google News?

Getting your site in Google News can skyrocket your website traffic and help you reach new audiences. It also helps build credibility and authority for your brand.

In this article, we’ll show you how to submit your WordPress site to Google News.

Submit WordPress Site to Google News

What is Google News?

Introduced in 2002, Google News is a news aggregator that shows the latest news and stories from the last 30 days.

The goal of Google News is to provide recent news update and headlines from around the world. It uses multiple sources to provide content and is available in numerous languages.

You can view Google News in a dedicated ‘News’ tab in Google when you search for a topic.

Google News preview

Additionally, Google News also appears at the top of the search results under ‘Top stories’ featured snippets.

Top stories snippet in Google

Why Submit Your WordPress Site to Google News?

Google News is one of the most trusted windows when people look for the latest stories from around the world.

Getting your WordPress site to show up in the Google News section can instantly boost your organic traffic and help you reach new audiences.

It also helps build credibility and authority for your brand because your site will likely be shown next to big brands like The Wall Street Journal, The New York Times, and more. This suggests that your site is trustworthy and offers quality information.

Besides that, getting featured in Google News can have a positive impact on your WordPress SEO. More websites will pick up your content as a source which provides backlinks. As a result, your website rankings will improve for other keywords.

Now that we know the benefits, let’s take a look at the eligibility requirements for being listed in Google News.

Requirements for Being Considered in Google News

Before you can submit your WordPress website to Google News, it’s important that you meet Google News policies.

Google has set specific content guidelines which determine if your content can qualify to appear in the Google News section. If your site doesn’t meet these guidelines, then it will be rejected.

For example, your content shouldn’t be dangerous, deceptive, hateful, or include violence or gore. Similarly, advertisements shouldn’t exceed your content, and you should disclose if your content is sponsored.

Besides that, you’ll need to provide clear dates, author bylines and information about the company or network behind the content.

There are more guidelines that you’ll have to comply with. We recommend following these policies very carefully to avoid your site being rejected for Google News.

That being said, let’s see how you can create a news sitemap for your WordPress, so you can submit it to Google News.

Creating a Google News Sitemap in WordPress

The first thing you’ll need to do is create a Google News sitemap for your website. After setting up a news sitemap, you can then submit your site to Google News.

A sitemap is a file that lists all your website content and helps Google find new articles and display them in the search results. It also makes the search engine bots crawl your site faster and improves the indexing of your content.

It’s important to note that Google News Sitemap is different from the regular XML sitemap. Google News Sitemap only includes news articles, and it allows the search engine to quickly discover content that needs to appear in the news section.

To create a Google News sitemap, we recommend using All in One SEO (AIOSEO). It’s the best WordPress SEO plugin and helps you optimize your site for search engines without hiring an expert or requiring technical knowledge.

AIOSEO

We’ll be using the AIOSEO pro version for this tutorial because it includes Google News sitemap and other powerful features like the redirection manager and schema markup. There is also a free version of AIOSEO that you can use to get started, but it doesn’t come with the news sitemap.

First, you’ll need to install and activate the AIOSEO plugin. If you need help, then please refer to our guide on how to install a WordPress plugin.

Upon activation, the plugin will launch a setup wizard. You can click the ‘Let’s Get Started’ button to configure AIOSEO on your site.

AIOSEO setup wizard

You can follow our beginner’s guide on how to properly setup All in One SEO for WordPress.

After that, you can head over to All in One SEO » Sitemaps from your WordPress dashboard and then navigate to the ‘News Sitemap’ tab.

News sitemap in AIOSEO

Next, you’ll need to click the ‘Activate News Sitemap’ button.

Once active, make sure that the toggle for ‘Enable Sitemap’ is switched on. There’s also an option to preview your news sitemap.

Next, you can scroll down and edit other settings related to the News sitemap.

For example, you can add the Publication Name that you entered in the Publisher Center. If you don’t enter a name, then AIOSEO will automatically use your site’s title.

Aside from that, you can select which content to include in the news sitemap under Post Types.

More news sitemap settings

You can include posts, pages, events, or check the box for ‘Include All Post Types’. It’s important to note that the Google News Sitemap will consist of content that’s published in the last 48 hours.

Next, you can click the toggle for ‘Advanced Settings’ and exclude any page or post that you don’t want included in the news sitemap.

Once that’s done, go ahead and click the ‘Save Changes’ button.

Advanced settings for news sitemap

AIOSEO will now create a Google News Sitemap for your WordPress website.

Submitting Your WordPress Site to Google News

Once your news sitemap is ready, you can now submit your website to Google News.

To start, you’ll need to go to the Google Publisher Center website and log in with your Google account.

Once you’re logged in, you’ll see a welcome notice. Simply click the ‘Got it’ button to continue.

Google Publisher Center welcome popup

After that, you can click the ‘Add publication’ button from the options given in the menu on your left.

Add publication to Google news

Next, a popup window will appear where you’ll have to enter the name of your WordPress blog, its URL, and select a location.

After entering these details, check the box to certify that your publication is principally and permanently located in the country you’ve selected and click the ‘Add publication’ button.

Enter publisher details

Your publication will now be added to the Publisher Center.

Go ahead and click the ‘Publication settings’ button for your publication.

Edit publication settings

On the next screen, you can edit your Publication name and select a ‘Primary language’ from the dropdown menu under Basic information.

Enter basic publication information

Next, you can scroll down and edit the Location for your publication and the Primary website property URL.

If you haven’t verified your website, then click the ‘Verify in search console’ button. This will open a popup asking you to open the Google Search Console so that you can verify your site’s ownership.

Edit location and verify ownership

For more details, please see our guide on how to add your WordPress site to Google Search Console.

After verifying your publication, you can head back to the Publication Settings and scroll down to view more options.

For instance, you can add additional website property URLs. Google News will use these links as a content source. Similarly, you can also add a contact email address for your publication.

Additional URLs and contacts

Once you’ve added these details, click the ‘Next’ button.

After that, you can add a logo for your publication. Google News offers multiple options for adding a logo for your site.

There is an option to enter a Square logo and a Rectangular logo. Plus, you can also upload custom fonts.

After uploading your logo, simply click the ‘Save’ button at the top and head back to the Publisher Center homepage.

Next, select your publication from the menu on your left and then click the ‘Google News’ box.

Get started with Google News

Go ahead and click the ‘Edit’ button to configure your site for Google News.

Edit Google news information

Next, enter Basic information including a Publication description, which acts as a meta description and helps people find your publication. Then you can select a Publication category from the dropdown menu.

Enter basic information

If you scroll down, you’ll see Distribution settings. By default, your content will be available in all countries and other Google products.

However, you can limit your site to appearing in certain regions by allowing and blocking specific countries from the ‘Countries’ dropdown menu. Similarly, you can also change the Google properties settings from the dropdown menu.

Don’t forget to click the ‘Next’ button when you’re done.

Add distribution information

After that, you’ll need to add Sections in Google News, which will appear as tabs. Sections help organize your content in Google News.

For example, you can add videos, web location, feed, or create a personalized feed for your site.

To begin, simply click the ‘+ New section’ button and select an option. For this tutorial, we’ll add a Feed.

Add sections
When you select Feed, a popup window will appear.

Go ahead and add a Section title, RSS feed URL that Google News will use as a content source, and choose who can view this section. After entering these details, click the ‘Add’ button.

Enter feed details

You can add as many sections as you want to organize your publication in Google News.

Besides that, you can also restrict certain sections of your publication in the Google News app for specific people under the ‘Access groups’ settings.

Access groups

When you’re done, don’t forget to click the ‘Next’ button.

After that, you can review any missing items in ‘Google News app publishing status’ and test your application.

review your publication

Simply click the ‘Review’ button for any item and see what information is missing or what requirements you haven’t met.

Before submitting your publication, you can scroll down to the ‘Testing your publication’ section click the ‘Follow publication’ button. This will make your site appear under Favorites in the Google News app.

Testing your publication

Next, you can go ahead and click the ‘Publish’ button under the Google News app publishing status’ box and sign off on terms of service agreements.

You’ve now successfully submitted your publication for review. It usually takes 2 weeks or more for the review process to complete.

We hope this article helped you learn how to submit your WordPress site to Google News. You may also want to check out our comparison of the best email marketing services for small business, and our guide on how to choose the best WordPress hosting for your business.

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 Submit your WordPress Site to Google News first appeared on WPBeginner.


December 07, 2021 at 04:00PM

Monday, December 6, 2021

How To Customize WordPress Reset Password Page

Do you want to create a custom password reset page in WordPress?

The default WordPress reset password form shows WordPress branding and does not match your site’s theme.

In this article, we’ll show you how to customize the WordPress reset password page.

How To Customize WordPress Reset Password Page

Why Customize the Reset Password Page in WordPress?

Your WordPress website comes with a powerful user management system that allows users to register for a user account, log in, and reset their password.

By default, these pages display the WordPress branding and logo. That’s fine if only you and your team log in to your admin area.

Default Reset Password Page

But if you’re running an eCommerce store or membership site, then your customers will also need to log in.

You will provide a much better user experience by customizing these user pages to match your website theme, display your own logo, and offer additional content.

You may have already followed our other guides on how to add a custom user registration form and login page to offer a better user experience.

Let’s take a look at how to customize the reset password page for an even more consistent user experience. We’ll cover three different methods:

Method 1: Customizing Reset Password Page Using Formidable Form

First, you need to install the Formidable Forms plugin. To learn more, see our step by step guide on how to install a WordPress plugin.

Formidable Forms is the most advanced WordPress form plugin in the market. While there’s a free version, you’ll need a Pro account to be able to create a reset password page.

Upon activation, you need to navigate to the Formidable » Add-Ons page. Here you should search for the User Registration add-on which is required to add a login screen and reset password page to the front end of your website.

Formidable Forms Add-Ons Page

Once you’ve found it, simply click the Activate button to enable the add-on.

Now you’re ready to create a custom reset password page.

You need to go to Page » Add New to create a new page. Next, you need to give your page a title and then enter the following shortcode [frm-reset-password] inside the WordPress content editor.

Create a New Reset Password Page and Enter the Shortcode

Make sure you add any additional content you would like to display on the page, then click the Publish button at the top right of the screen.

Finally, you need to make sure that WordPress will use this page when resetting a password. To do that, head over to the Formidable » Global Settings and then click the ‘Registration’ tab in the menu.

Formidable Forms Global Settings Registration Page

From here you need to find the ‘Reset Password Page’ option and then simply select the page you just created from the drop down menu.

Don’t forget to click the ‘Update’ button at the top of the screen to store your settings.

You can now visit your website to see the custom reset password page in action.

Formidable Forms Reset Password Page Preview

Method 2: Customizing Reset Password Page Using Theme My Login

Theme My Login is not very customizable, but it’s a simple and free way to change your login and reset password pages to match your WordPress theme.

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

Upon activation, Theme My Login automatically creates URLs for your custom login, logout, registration, forgot password, and reset password actions.

You can view or customize these URLs by visiting Theme My Login » General page. Scroll down to the ‘Slugs’ section to modify these URLs used by the plugin for login actions.

Theme My Login Slugs

Notice the slugs for ‘Lost Password’ and ‘Reset Password’. We’ll leave the default settings and start by creating a new lost password page.

You need to head over to Page » Add New to create a new WordPress page. Next, you need to give your page a title and then enter the following shortcode [theme-my-login action="lostpassword"] inside the content area.

Theme My Login Shortcode

You also need to change the page’s URL slug to lostpassword so that Theme My Login will redirect the normal lost password URL to this page.

Once you’ve added any additional content you want on the page, you can click the ‘Publish’ button and preview it to see your custom login page in action.

Theme My Login Reset Password Preview

Next, you will need to repeat the process to create a custom reset password page. You will need to add the shortcode [theme-my-login action="resetpass"] to the content of the page, and change the URL slug to lostpassword.

You may not need to create a completely custom WordPress login page for your website. In fact, a lot of websites just replace the WordPress logo and logo URL while still using the default login page.

At the end of our guide on how to create a custom WordPress login page, we show you two ways to replace the login screen logo with your own logo, one using a plugin and the other using code.

The best thing is, both of these methods will also automatically change the logo on the reset password page as well.

We hope this tutorial helped you learn how to customize the WordPress reset password page.

You may also want to learn how to create a free business email address or check out our list of must have plugins to grow your site.

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 Customize WordPress Reset Password Page first appeared on WPBeginner.


December 06, 2021 at 04:00PM