Development Archives - SecondLineThemes Premium WordPress Themes & Development Wed, 10 Nov 2021 11:56:52 +0000 en-US hourly 1 https://secondlinethemes.com/wp-content/uploads/2020/09/cropped-icon-32x32.png Development Archives - SecondLineThemes 32 32 First Impressions Count: How to Attract New Listeners with Your Home Page (5 Tips) https://secondlinethemes.com/attract-new-listeners-with-your-home-page/ Wed, 10 Nov 2021 11:56:52 +0000 https://secondlinethemes.com/?p=53466 Your podcast website is as important as your podcast and episodes, so perfect it and make sure it’s beautiful and loading rapidly is a great idea. Are many of your visitors leaving almost as soon as they reach your site? If so, your home page may not be making the right first impression. Users typically […]

The post First Impressions Count: How to Attract New Listeners with Your Home Page (5 Tips) appeared first on SecondLineThemes.

]]>
Your podcast website is as important as your podcast and episodes, so perfect it and make sure it’s beautiful and loading rapidly is a great idea. Are many of your visitors leaving almost as soon as they reach your site? If so, your home page may not be making the right first impression. Users typically form an opinion about a web page within 50 milliseconds. That’s two to three times faster than the average human blink.

Fortunately, there are strategies you can use in your home page design that encourage visitors to stick around and take action. As we’ll see, a pinch of psychology and a dash of methodical testing can go a long way.

In this post, we’ll discuss what a great first impression can do for your podcasting business. Then we’ll walk through five ways to improve your home page and attract more listeners. Let’s get started!

Why First Impressions Are Important

How much does your site’s visual design impact how visitors perceive it? The answer is quite a bit.

Right from the initial content loaded onto the page, the visitors can get a first impression of your website and your podcast. It essentially gives them a quick background for your own storyline.

With over two million podcasts out there, this space is becoming very crowded. If your site doesn’t lure listeners in right away, you may lose them to the competition.

How to Attract New Listeners With Your Home Page (5 Tips)

Your home page isn’t about you as much as it is about your visitors. Consider your own experiences browsing the web. When you access a new website, do you read through every word?

The answer is probably not. Most likely, you’re looking for what the site can do for you. If you can’t figure that out quickly, you’ll leave.

However, if the benefit to you is clear, you’re more likely to stay, explore, and become a listener. Here are five ways to make that happen for your podcast site’s visitors.

1. Make Your Hero Banner Heroic

A hero banner is a large image at or near the top of the page, often with some overlay text:

Being Boss podcast site screenshot

The hero banner is a great place to set a tone and showcase your brand story. You can also use it to engage visitors by including a clear Call To Action (CTA).

Whatever image you choose, make sure it’s visually appealing and evokes thoughts or emotions by association. For example, your face may be one of your best marketing tools.

We make immediate emotional connections with human faces. Therefore, consider taking a high-quality hero banner photo that shows your face (and that of your co-stars if relevant) prominently.

2. Showcase Both Audio and Visual Content

As the home of a podcast, your website has an advantage that many other sites don’t: it combines both visual and audio content. This is a powerful combination that impacts two senses at once.

For an example, check out the strong visual elements of the Twenty Thousand Hertz podcast:

Twenty Thousand Hertz screenshot

These visuals make it crystal-clear what the tone of the podcast will be, and make the visitor want to learn more.

You don’t need visuals this elaborate. However, it’s best not to take the easy way out and use your platform’s default styling. Instead, deliberately choose colors and images that reinforce your podcast’s theme and tone.

If you need to source free images and videos, you can start by browsing royalty-free image sites such as Pixabay and Pexels.

3. Feature a Strong Call to Action Above the Fold

You may think that unlimited options make people happy, but it can create indecision. When a website doesn’t offer a clear course of action for its users, they may get confused and leave.

Fortunately, you can use a Call to Action (CTA) to signal to visitors what specific step they should take next. The most effective home page CTAs are usually simple. You might use phrases like “Listen now”, “Subscribe to our podcast“, and “Get in touch”.

A site’s main CTA is often placed in a button ‘above the fold’. That’s the part of the website visitors can see without scrolling:

Boston Content Screenshot

This CTA is clear and concise. In addition, it makes the benefits of taking action very clear.

You can CTAs to engage your visitors from their first interaction with your podcast site. Keep them brief and simple, but make sure it’s obvious to users what will happen when they click on the link or button.

4. Design with Usability in Mind

Usability refers to the ease with which a user can interact with an interface. Is your website easy for a first-time visitor to figure out? Are interactions quick and frictionless? Are the pages pleasant to interact with?

These are all factors that go into a usable interface. If your site isn’t usable, your visitors are less likely to stay and become fans.

Fortunately, you don’t need to be an expert to create a usable website. A basic understanding can go a long way.

First and foremost, make sure your layout is universally familiar. For example, don’t put the main navigation at the bottom of the page, or anywhere else that forces users to search for it. It’s best not to try and reinvent the wheel. Simple buttons and links have worked for decades, so you don’t need to come up with fancy new interaction schemes.

Most importantly, keep your layout simple and uncluttered. It should always be easy for your visitors to figure out where to click to get what they want.

5. A/B Test Your Site

Finally, don’t forget to test your website’s design. A/B testing, or split testing, is a method for discovering what works on your site and what doesn’t. You create two (or more) versions of a page, and randomly serve one or the other to each visitor.

From there, you can determine what’s working based on your goals. Which version of your site gets more conversions? Which one do users engage with the most? The least?

To conduct A/B testing, you can use one of many user-friendly tools. Some are free but offer only basic functionality. In many cases, that’s all you’ll need for a straightforward podcasting site.

Conclusion

Building website content that engages visitors doesn’t have to be daunting. By making a few tweaks to your home page, you can draw people in and keep them around long term.

To recap, here are the best strategies for grabbing attention with your podcast website’s home page:

  1. Create an effective hero banner.
  2. Use both audio and visual content.
  3. Have a strong above-the-fold CTA.
  4. Make your home page usable.
  5. Perform A/B testing.

You can browse our blog for more information on how to start and run your podcast website!

The post First Impressions Count: How to Attract New Listeners with Your Home Page (5 Tips) appeared first on SecondLineThemes.

]]>
Google Maps Not Working in WordPress https://secondlinethemes.com/google-maps-not-working-wordpress/ Mon, 27 Mar 2017 10:16:29 +0000 http://secondlinethemes.com/?p=331 Displaying a Google Maps element on your WordPress website is very common these days. You’ll rarely see a company or a product website without a proper location/map area. But whenever you find a theme or a plugin that uses Google Maps, there’s an extra step involved to make the map work. For new domains, the […]

The post Google Maps Not Working in WordPress appeared first on SecondLineThemes.

]]>
Displaying a Google Maps element on your WordPress website is very common these days. You’ll rarely see a company or a product website without a proper location/map area. But whenever you find a theme or a plugin that uses Google Maps, there’s an extra step involved to make the map work. For new domains, the map often shows as a gray area and does not work at all. You are probably getting the “Oops! Something went wrong.” Google Maps Not Working error. Let’s explore the possible methods to solve the error –

Fix the Google Maps Not Working Error

The Google Maps Not Working error in WordPress appears because you need to add an API key to make the maps work properly. This is a requirement since June 2016, and it is related with how Google handles traffic for the Google Maps service. Follow the steps bellow to properly display the maps on your website:

1. Getting an API Key

Head out to Googles Maps JavaScript API website. You should see a few clear steps on how to get the API key. Almost all Google services require authentication. This is ultimately a good thing, because you can closely monitor requests and API usage from the Google console. For the Google Maps specifically, you can choose between 2 packages:

  • Standard API users. This is good for most people, as you get 25,000 map loads in 24 hours. If you exceed this limit, you can setup a pay-as-you-go billing to adjust things depending on your website traffic.
  • Premium Plan users. This package is paid one, but you get significantly higher map load limit as well as some other advantages like 24-hour technical support. This plan is intended for websites that receive large amounts of traffic, and 90% of the time, it doesn’t apply to WordPress websites and blogs.

2. Registering the Key with your URL

Now that you know the difference, you can start with the free Standard API package by clicking on the blue “Get a Key” button. Note that you must have a Google Account and be signed in when you do this. Once you click the button, a window will pop-up on the screen asking you for a project name and TOS agreement. The name can be anything you like, but it is conventional to write your website’s name.

Make sure you register the Google Maps API with your URL, or else you would still have the Google Maps Not Working error. We must associate the URL with our new Google Maps API.

After a few seconds, you’ll get a “You’re all set!” window with your API key. You need to copy this key, because now we’re going to use it in WordPress. To improve your website’s or app’s security, you can restrict the key’s usage from Google’s API console.
Using Your API Key in WordPress

Wrapping Up

Sometimes, the Google Maps still works on older domain names. If we wish to display the Google Maps on a new domain, we must register an API key or else we may get the “Oops! Something went wrong.” Google Maps Not Working error. displayed when you were checking it out, is because the developers were using their own API key for previewing the theme’s features. This also applies to plugins. To display the map with your location, you must use the API key generated in the section above. How can we do that? Well, it all depends on the package. The developers either reserved a field in the theme/plugin settings for the API key, or you need to find the API request into the code, and insert it yourself.

To find out which option applies in your case, go through the options page, and look for Google Maps API key section. You can also ask around on forums and support pages. If there is a field, you just paste in your key and you’re all set! Now, when you reload the website, your location should be displayed.

 

 

If you need a savvy WordPress developer to help you out, please consider Hiring an Expert.

The post Google Maps Not Working in WordPress appeared first on SecondLineThemes.

]]>
How to Add Google Fonts in WordPress https://secondlinethemes.com/add-google-fonts-wordpress/ Mon, 06 Feb 2017 12:08:01 +0000 http://secondlinethemes.com/?p=309 Doing things like adding adding custom fonts to your theme or loading maps, usually requires coding and working with different APIs. But luckily, there are some useful plugins that do all of that dirty work for us! In this article, we’ll see how you can make your pick from 800+ Google Fonts with a few […]

The post How to Add Google Fonts in WordPress appeared first on SecondLineThemes.

]]>
Doing things like adding adding custom fonts to your theme or loading maps, usually requires coding and working with different APIs. But luckily, there are some useful plugins that do all of that dirty work for us! In this article, we’ll see how you can make your pick from 800+ Google Fonts with a few clicks in your WordPress admin panel — no coding required. Let’s take a closer look at the Easy Google Fonts plugin, and how we can use it to pick any front we like from Google’s library for our WordPress theme.

Getting to Know Easy Google Fonts Plugin

The first thing you need to do, is to install and activate the Easy Google Fonts plugin. You can find the plugin settings under Settings->Google Fonts. Once this is done, it’s time to get familiar with what this plugin can do for you, and how you can go about setting your favorite font from Google’s font API.

As we mentioned earlier, Easy Google Fonts is a simple solution for adding fonts in your WordPress theme without any coding or configuration. Moreover, it integrates with the WordPress Customizer, so you can easily preview the fonts in real-time on your website. This is especially helpful when experimenting with different fonts.

This plugin works with any theme out there, so you don’t have to worry about compatibility issues. Besides adding fonts, you can create specific font colors for different elements on your page. Once you do setup font colors in the settings page, they are instantly available in the WordPress customizer.

Here’s an overview of the most useful features:

  • Live customizer preview
  • Entire Google fonts library at your disposal
  • Compatibility with every WordPress theme
  • Automatic background updates (Stays up to date with Google’s font library at all times)
  • Font colors
  • Translation ready

To start using this plugin, go into the WordPress customizer and click on Typography. From there you will be able to select a Font Family, weight, decoration, transform, etc. Once you’re satisfied with how your website looks in preview mode, click Save & Publish, and you’re all set! For font colors, check out the plugin’s settings page.

The post How to Add Google Fonts in WordPress appeared first on SecondLineThemes.

]]>
3 Steps for Advanced Custom Fields Integration https://secondlinethemes.com/3-steps-advanced-custom-fields-integration/ Sun, 22 Jan 2017 18:57:10 +0000 http://secondlinethemes.com/?p=296 Custom Fields in WordPress with Advanced Custom Fields – Once you created a custom post type and taxonomy, it is time to add some special fields to it, and further customize WordPress to fit your needs. These custom fields in WordPress help you build new functionality to your site by creating populating different field types […]

The post 3 Steps for Advanced Custom Fields Integration appeared first on SecondLineThemes.

]]>
Custom Fields in WordPress with Advanced Custom Fields – Once you created a custom post type and taxonomy, it is time to add some special fields to it, and further customize WordPress to fit your needs. These custom fields in WordPress help you build new functionality to your site by creating populating different field types in the admin panel. What type of field types? From text, textarea, checkbox, radio and select, all the way to files, images, galleries and color pickers.

Once you have these fields tied up to your custom post type, and you insert some values, you can easily display them in front-end pages. For instance, we can create a custom price and discount text fields for our post type, and then, display them anywhere we like in our template. Let’s see how we can do this using one of the best rated plugins in the WordPress directory — Advanced Custom Fields.

1. Advanced Custom Fields Introduction

Advanced Custom Fields is a free plugin for visually creating and managing custom fields in WordPress. Moreover, it is a framework with great plugins (add-ons), documentation and community. ACF has a really simple and powerful API with functions for everything you’d possibly need, in order to manipulate the custom fields and their values. Each of these functions are explained in detail and demonstrated with an easy-to-follow examples.

To install the plugin, follow this link. Once you activate the plugin, visit ACF’s page in the admin panel.

 

2. Creating Custom Fields

Go to Custom Fields, and click on Add New to create a new field group. Let’s name the field group Reviews CPT — the name of a custom post type we created in one of the previous articles. Now, we can start adding custom fields to it. For starters, we’ll create two fields: price and discount. Click on the +Add Field button, and set the values as follows:

  • Field Label (required), is the name that will appear in the post edit page. We can set it to Price.
  • Field Name (required), is the “slug” that must be a single word with no spaces. Dashes and underscores are allowed. This is the name we’ll use to access this field’s value in the front end. Let’s set this to review-item-price.
  • Field Type (required), is one of the field types we mentioned in the intro of the article. You have a lot of choices here, so pick accordingly. For this example, we will set the field type to number.
  • Field Instructions (optional), is the description box that will help authors who submit data into the fields. Set it to something like: Here goes the price of the item that’s being reviewed.

As you choose different field types, additional options will be displayed to further customize your field. For example, if you pick a text field type, you can specify stuff like default value, prepend, append and character limit.

Repeat the same process to create the discount custom field. You can set its type to text, and slug to review-item-discount.

Once finished with the second field, we can let ACF know which custom post type we want to link with these fields. This is the location box. Use the following logic:

Show this field group if: Post Type is equal to reviews.

This will make the custom fields accessible only in our reviews post type, when we’re trying to add a new article.

The final step is to click Publish, visit the Reviews section on the admin panel and click on Add New Review (or Add New). Once you do this, you will notice the 2 fields in the bottom — right bellow the WYSIWYG editor. Create a review with these values and publish it.

 

3. Displaying Custom Fields

There are million things you can do with these fields, but for the sake of just getting started with ACF, let’s just display them on the single post page.

Navigate to your theme files, and if you haven’t already, create a single-reviews.php file (single-{post_type_name}.php). This will be a custom template file specifically for the reviews post type, and the place where we display our custom fields.

Why not use the already existing single.php? Because this template file applies to every post type on our website. Remember that we specified in the plugin to only show the fields in our reviews CPT. When you open a regular post type, the values won’t show up.

Copy all the contents of single.php into single-reviews.php. Then, in single-reviews.php add the following code, 1 line upper from the_content() function:

<?php if (get_field(‘price)): ?>

Item price: <?php the_field(‘price)); ?>

<?php endif;?>

The get_field() function will return the value of the specified field. This is good, because we can check whether a value is defined, before we try to display it. If the field doesn’t have a value, the function will return a false, and the if statement won’t execute. At the end, the_field() simply echoes the field in a h2 tag. You can repeat the same process for the discount field.

When you visit your article, you should see a Price: $600 and Discount: 20% (or whatever values you put) before the review content. Pretty powerful, isn’t it!

The post 3 Steps for Advanced Custom Fields Integration appeared first on SecondLineThemes.

]]>
Creating a WordPress Child Theme https://secondlinethemes.com/creating-child-theme/ Fri, 13 Jan 2017 13:51:05 +0000 http://secondlinethemes.com/?p=291 WordPress is open source — meaning you can look up the code and see/improve how the CMS works. However convenient this may sound in theory, very few people would need to change the WordPress core. Themes on the other hand, require tons of tweaking and customizations. If some option isn’t part of the theme’s pre-built […]

The post Creating a WordPress Child Theme appeared first on SecondLineThemes.

]]>
WordPress is open source — meaning you can look up the code and see/improve how the CMS works. However convenient this may sound in theory, very few people would need to change the WordPress core. Themes on the other hand, require tons of tweaking and customizations. If some option isn’t part of the theme’s pre-built admin panel, you will need to make the modification in question manually. And this is where child themes come into play — as the recommended method for customizing any WordPress theme. In this article, we’ll learn how we can create a WordPress child theme by properly enqueuing parent theme styles.

Why You Need to Use a Child Theme?

The most important thing to understand about a child theme, is that it inherits all of the features and appearance from its parent theme. We can make changes to the parent theme — without affecting or changing its code. Why is this important? Because when you modify some files directly and the theme is updated, you may lose your customizations. By using a child theme, you will risk that our changes are deleted or overwritten — no matter how often the original theme gets updated.
Create a WordPress Child Theme — The Right Way
We’re going to create a child theme for the theme Twenty Sixteen. Every WordPress child theme needs 1 directory, and 2 main files: style.css and functions.php. So, let’s do exactly that.

1. From your WordPress root directory, go to wp-content/themes.
2. In the themes directory, create a new folder called twentysixteen-child (or any other name you find suitable). Make sure the name is in lowercase letters. If there’s more than one word, you can separate it with a dash (—).
3. Open your text editor, and within our newly created directory for the child theme, create 2 files: style.css and functions.php.

Now, let’s add a few required comments in our style.css, so that WordPress can detect the child theme:

/*
Theme Name: Twenty Sixteen Child
Theme URI: http://example.com/child-theme-preview
Description: Lorem ipsum dolor sit amet.
Author: John Doe
Author URI: http://example.com
Template: twentysixteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: lorem, ipsum, dolor, sit, amet
Text Domain: twenty-sixteen-child
*/

Although some of these comments are optional, it’s a good practice to include them all. WordPress will use this information to populate some fields in the Appearance section, and to detect the parent theme. Two lines are super-important: Theme Name and the template.

Theme Name is what WordPress will call your child theme throughout the admin panel. The template line is connected with the directory name of the parent theme. So please check your wp-content/themes directory, and see how your parent theme’s directory is named. If you don’t get the template line right, you won’t be able to activate the child theme.

There are two ways we can accomplish this. The first is to use @import in the style.css — which is easier, but with a significant downside. It increases the style load time, and it is no longer the preferred method. That’s why we will enqueue the parent theme styles more efficiently using functions.php.

Open functions.php and write the following code:

function import_parent_theme_styles() {
wp_enqueue_style(‘parent-theme-styles’, get_template_directory_uri() . ‘/style.css’);
}
do_action(‘wp_enqueue_scripts’, ‘import_parent_theme_styles’);

That’s it! Save functions.php, and activate your child theme. It should look exactly the same as your parent theme. But now, whenever you want to change the appearance, you can do that by writing CSS into your child theme’s style.css. Moreover, you can change entire template files in your child theme, and WordPress will know to load those, instead the template files in the parent theme.

The post Creating a WordPress Child Theme appeared first on SecondLineThemes.

]]>
How to Display Custom Post Types in WordPress https://secondlinethemes.com/display-custom-post-types-wordpress/ Wed, 04 Jan 2017 10:56:39 +0000 http://secondlinethemes.com/?p=265 Need help with your WordPress Project? Hire an experienced developer today! In the previous article in this series, we’ve created a Custom Post Type, it’s learn how you can display it on your website. Just to recap, we created a custom post type called Podcast, and a custom taxonomy — Podcast Category. In this guide, […]

The post How to Display Custom Post Types in WordPress appeared first on SecondLineThemes.

]]>
Need help with your WordPress Project? Hire an experienced developer today!

In the previous article in this series, we’ve created a Custom Post Type, it’s learn how you can display it on your website. Just to recap, we created a custom post type called Podcast, and a custom taxonomy — Podcast Category. In this guide, we will discover 3 ways you can display articles from the Podcast post type on your website. Before trying these methods, make sure you have at least 1 articles published under your CPT. Our WordPress Podcast Themes can work with a custom post type and by using the regular “Posts” type as well!

3 Ways To Display Custom Post Types in WordPress

1. Using the Default Archive Template

In order for this to work, you need to go to Settings->Permalinks, and check what type of link structure you’re using. Chances are you’re using SEO friendly permalinks. From here, you need to navigate to Appearance->Menus, and add a custom link to your navigation.

If you’re on a fresh WordPress installation, your CPT link will look like this: www.example.com/?post_type=podcasts.

But if you changed the permalink structure to display links in more SEO and user friendly manner, your post type URL can look like this: www.example.com/podcasts.

Depending on your setup, you need to get this link, and add it in your menu as a custom link. Change example.com with your website’s name, and podcasts with your CPT name (if they are different). Then, set the name of the menu item to Podcasts, and save/update your menu.

The next time you open your website, you will see Podcasts on your menu. If you click on this link, it will display the articles from Podcasts post type using the default archive.php template.

2. Using Custom Templates for Archive Pages and Single Post Entries

If you don’t like how the default archive.php template displays your Podcast posts, you can create a custom template. All you need to do here, is create a file called archive-podcasts.php in your theme’s directory. If such file exists, WordPress will automatically use this template file when displaying content from your custom post type.

If you open Podcassfrom your menu, you’ll see a blank page, because WordPress loads your custom template — which is currently empty. A good practice is to copy the contents of archive.php into your new file, and start making modifications from there.

Another thing you can do, is to create a custom template for your single entries. By default, WordPress uses single.php to display single entries on the front-end.

Similarly, you can create a file called single-podcasts.php to display your single articles from Podcast CPT in a different way. This comes in handy when you have custom fields or taxonomies. To get started, you can copy the contents from single.php and start making changes per your needs.

3. Querying Custom Post Types on the Landing Page Alongside Regular Posts

A more advanced approach when dealing with custom post types, is to display them alongside other types of content on your front page. In our example, this would mean to display podcast and blog posts together on the landing page.

By default, WordPress uses a template file called index.php (if there’s no front-page.php or home.php) to display posts on the landing page. We can modify our theme’s index.php, and make it load our Podcast post type by creating an additional query to the database.

This is an example of how a simple index.php file would look like, and what changes we can apply to it to reach our goal:

<?php get_header(); ?>
<div id="primary" class="content-area">
	<main id="main" class="site-main" role=“main”>
		<?php if (have_posts()) : ?>
			<?php while (have_posts() : the_post());
				// This is the main WordPress loop which loads the default “blog” posts. As an example, we will display only the article’s title.
				echo the_title();
			endwhile; ?>
		<?php endif; ?>

You need to add the following piece of code after the main WordPress loop in your index.php file.

		// Display Podcasts CPT
		<?php 
			$args = array(‘post_type’ => ‘podcasts’, ‘posts_per_page’ => ‘3’);
			$myQuery = new WP_Query($args);
		?>
		<?php if ($myQuery->have_posts() : ?>
			<?php while ($myQuery->have_posts() : $myQuery->the_post(); ?>
				<?php // Dislpay the podcast title
				echo the_title(); ?>
			<?php endwhile;  wp_reset_postdata(); ?>
		<?php endif; ?>
	</main>
</div>

This is how we query the WordPress the database, and load articles from custom post types on the landing page. Two things are important here:
1. Make sure to use the “=>” symbol when creating the $args array for the WP_Query object. Use “->” symbol when trying to call a function of a class like this: $myQuery->have_posts().
2. Make sure to call the wp_reset_postdata() function after the endwhile; statement. This function restores the global $post variable of the main query after a secondary query loop has been executed. More info on this function can be found here.

Note: If you’re making modifications to existing files, or creating new ones, it’s always good to make those changes from a child theme. This way, when the theme updates, you get to keep all your changes.

The post How to Display Custom Post Types in WordPress appeared first on SecondLineThemes.

]]>
WordPress Custom Taxonomies: Beginner’s Guide https://secondlinethemes.com/wordpress-custom-taxonomies-guide/ Wed, 04 Jan 2017 10:47:07 +0000 http://secondlinethemes.com/?p=262 Last week, in the previous article, we introduced custom post types in WordPress, as a powerful tool to customize your website and make it fit your specific needs. In the process of creating our very own post type called Reviews, we mentioned the term taxonomies. In fact, we added a taxonomy called Review Type to […]

The post WordPress Custom Taxonomies: Beginner’s Guide appeared first on SecondLineThemes.

]]>
Last week, in the previous article, we introduced custom post types in WordPress, as a powerful tool to customize your website and make it fit your specific needs. In the process of creating our very own post type called Reviews, we mentioned the term taxonomies. In fact, we added a taxonomy called Review Type to the custom post type. This section is all about understanding WordPress Custom Taxonomies. So, let’s get on with it!

What are Custom Taxonomies in WordPress?

Taxonomy is the science of defining and naming groups of biological organisms with shared/mutual characteristics. It refers to classification and grouping of such organisms.

With WordPress, Custom Taxonomies are just a way to group similar pieces of content into separate groups. The names for different groups in a taxonomy are called terms. This allows users to publish and display posts in a more organized and structured manner.

Even though you may not be familiar with the technical term “taxonomy” and its origins, you have already used it in WordPress. How? Well, by using categories and tags to group your posts! These are the two most popular taxonomies in WordPress.

Custom taxonomies come into play when you don’t want to mix your different post types in same taxonomy groups. While you can always use the existing WordPress taxonomy “category”, and create different terms, it’s good to have separate taxonomies for different post types. Why? Because having the terms Digital Marketing, How To and Smartphone Reviews in the same taxonomy can make your content look really messy, really fast.

Taxonomies can be hierarchical, and have parent-child taxonomy relation. This means that you can have main a main term like Laptop Reviews, and then for instance, 3 sub-terms: Budget, Mid-range and High End.

Example

If your website is about electronic reviews, you can separate your content in 3 main taxonomies. The first (in-built) taxonomy “category” can be used for your blog posts, and contain terms like Digital Marketing and How To. This taxonomy will be attached to your default post type “post”. The second and (custom) taxonomy “review-type”, can hold everything related to electronic reviews. It will be attached to the custom post type “reviews”. The third (in-built) taxonomy is tags — and can be used for everything.

2 Ways for Creating WordPress Custom Taxonomies

Enough with the theory, let’s move forward, and create a hierarchical custom taxonomy called Review Type.

Using a Plugin

If you don’t feel comfortable with coding, you can use Custom Post Type UI. This plugin has a fairly simple user interface that allows you to create a custom taxonomy within minutes! Here’s how to create a custom taxonomy with this plugin:
1. Download, install and activate Custom Post Type UI.
2. Navigate to CPT UI from your admin panel, and click on Add/Edit Taxonomies.
3. Under basic settings, in the field taxonomy slug, write a unique slug for your taxonomy. In our case, this is going to be two words separated with a dash: review-type.
4. Next is plural label, used for the admin panel. We will set it to “Review Type”.
5. Singular label is very similar to the label from Step 4, but it applies in situations when WordPress needs to use a singular name of a taxonomy. Set this to “Review Type” as well.
6. Go to Attach to Post Type, and select the post type on which you want to attach this taxonomy. If you’re following us from the previous article, select Reviews.

Notice that the singular and plural labels are identical for our custom post type. In our case, this really doesn’t make a difference. But if we had a custom post type like movies, and created a taxonomy called Actors, our plural label will be Actors, and the singular label Actor.
At the end of the day, how users name labels is totally up to them — as they are just visual enhancements for better UI and UX.

Manually

Go to your theme’s functions.php, and at the end of the file, write the following code:

// Creating a custom taxonomy for Reviews CPT
function create_reviews_taxonomy() {

// Add new taxonomy, make it hierarchical like categories
  $labels = array(
    'name' => _x( 'Review Type', 'taxonomy general name' ),
    'singular_name' => _x( 'Review Type', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Review Types' ),
    'all_items' => __( 'All Review Types' ),
    'parent_item' => __( 'Parent Review Type' ),
    'parent_item_colon' => __( 'Parent Review Type' ),
    'edit_item' => __( 'Edit Review Type' ),
    'update_item' => __( 'Update Review Type' ),
    'add_new_item' => __( 'Add New Review Type' ),
    'new_item_name' => __( 'New Review Name' ),
    'menu_name' => __( 'Review Type' )
  );

// Register the taxonomy
  register_taxonomy( 'review-type', array( 'reviews' ), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
  ));

}

// Hook into the init action and call create_reviews_taxonomy when it fires
add_action( 'init', 'create_reviews_taxonomy', 0 );

Similar to when we created a custom post type, we have the $labels array for UI visuals on the WordPress panel. Then, we call the register_taxonomy function which takes as an argument 3 parameters: the slug of the taxonomy, the post type to which it connects (passed as an array, because it can be applied to more than one post type) and core settings. The last parameter is an array composed of main settings like hierarchical, show_ui, etc. You can read up on what each specific field represents in the WordPress Codex, and make changes if needed.

The post WordPress Custom Taxonomies: Beginner’s Guide appeared first on SecondLineThemes.

]]>
WordPress Custom Post Types – Beginner’s Guide https://secondlinethemes.com/wordpress-custom-post-types/ Wed, 04 Jan 2017 10:29:57 +0000 http://secondlinethemes.com/?p=258 WordPress isn’t just a tool for writing and publishing blog posts anymore. Over the years, it has evolved into an extensible, flexible and robust content management system. WordPress is slowly but surely moving towards becoming a fully-fledged framework for building web apps. One of the things that makes this CMS so adjustable, is Custom Post […]

The post WordPress Custom Post Types – Beginner’s Guide appeared first on SecondLineThemes.

]]>
WordPress isn’t just a tool for writing and publishing blog posts anymore. Over the years, it has evolved into an extensible, flexible and robust content management system. WordPress is slowly but surely moving towards becoming a fully-fledged framework for building web apps. One of the things that makes this CMS so adjustable, is Custom Post Types.

By default, WordPress comes with 5 content post types, of which, 2 should sound very familiar to you: post and page. But users can create as many custom post types as they need, and use them for tweaking WordPress to meet their needs. In this article, we will get familiar with WordPress custom post types, and how they can help you build awesome websites. We will cover two ways for creating custom post types: manually and by using a plugin.

WordPress Custom Post Types

Out of the box, WordPress comes with the following post types:

  • Post
  • Page
  • Revision
  • Attachment
  • Navigation Menu

WordPress treats each of its post types differently — by allowing unique options and features. A simple example, would be categories and tags, which are exclusive to the post type “post”. You can set your blog post to a specific category, but you can’t do the same for a static page. Pages on the other hand, can have parents and templates.

The post types mentioned so far are reserved by WordPress. Users can create their own custom post types to extend the website’s functionality, and better organize their content. Usually, creating custom post types goes hand in hand with creating custom fields and custom taxonomies, that allow you to insert unique content and options — specific to a given post type. But let’s leave these for another time, and focus on setting up a unique post type for our website.

Custom Post Type Examples

A post type can be any type of content that you need for your website. Let’s say that we have a podcast website that needs to display podcast episodes, and needs to publish occasional yet separate blog posts. Now, if we mix all of our content (Podcasts and blog posts) in one place, our content section will become really messy really fast. That’s why for our occasional blog posts, we will use the default post type “post” in WordPress, that allows us to use the default taxonomies: categories and tags.

As for our Podcast section, we will create a custom post type called Podcast. This way, we can separate the two different content types on the website, and have them organized in a neat way. Later, we can create custom fields for our podcasts section like episode duration, show hosts, links and so on. Additionally, we can setup custom taxonomies specific to this type of content, like Podcast categories, Podcast Shows and more. You see where this goes, and how much flexibility WordPress offers in terms of content manipulation and structure.

Creating a Custom Post Type in WordPress

There are 2 ways you can create a custom post type in WordPress: manually (fairly easy, but requires some familiarity with coding) and using a plugin (much easier method, but requires you to keep the plugin installed). Which one should you choose? Having many plugins can cause you headaches because of incompatibility, performance issues and bad code. If you already have tons of plugins installed, you may want to get your hands dirty this one time. We will cover both methods, and you decide which one works for you the best.

Using a Plugin

There are a handful of plugins for creating custom post types. One of the most popular ones, is Custom Post Type UI — which also allows you to create custom taxonomies for your post type.

Important note: Post types that are created with a plugin will disappear if you remove the plugin in question. The data will be in the database, but your custom post type will become unregistered, and not reachable from the admin area.

The interface of this plugin is pretty intuitive and simple. You click Add New, and then provide a post type name, label, singular label and description for the custom post type. Not that the 5 WordPress post types are reserved, and you can’t use those names. Here’s an example of what you should input:

Post Type Name: Podcasts
Label: Podcasts
Singular Name: Podcast
Description: Post type for podcasting

The singular name field is used by WordPress to display some UI elements and actions like Add New Podcast.

Manually

To create a custom post type manually, you need to modify your theme’s functions.php. Use your favorite FTP client and login to the server on which your website is hosted. Once connected, you need to:
1. Navigate to wp-content -> themes -> your theme
2. Open functions.php
3. If you are using a child theme, and there is no such file, create it.
4. Insert the code bellow.

As per our example, we need to create a podcast custom post type. Here’s the code for that (from step 4: the following code goes into your functions.php file):

// Registering CPT
function podcast_post_type() {

//Setting up the user interface labels for podcasting CPT
$labels = array(
'name' => _x( 'Podcasts', 'Post Type General Name' ),
'singular_name' => _x( 'Podcast', 'Post Type Singular Name' ),
'menu_name' => __( 'Podcasts' ),
'name_admin_bar' => __( 'Podcast' ),
'parent_item_colon' => __( 'Parent Podcast' ),
'all_items' => __( 'All Podcasts' ),
'add_new_item' => __( 'Post New Podcast' ),
'add_new' => __( 'New Podcast' ),
'new_item' => __( 'New Podcast' ),
'edit_item' => __( 'Edit Podcast' ),
'update_item' => __( 'Update Podcast' ),
'view_item' => __( 'View Podcast' ),
'search_items' => __( 'Search Podcasts' ),
'not_found' => __( 'No Podcasts found' ),
'not_found_in_trash' => __( 'No Podcasts found in trash' )
);

//Setting up other options for Podcasts CPT
$args = array(
'label' => __( 'Podcasts' ),
'labels' => $labels,
'description' => __( 'Creating and managing podcasts' ),
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'revisions', 'custom-fields' ), //Initially supported features
'taxonomies' => array( ‘podcast-category'), //If custom taxonomies exist, insert their names in the array
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
);

//Registering custom post type
register_post_type( 'podcasts', $args );

}

// Hook into init action
add_action( 'init', 'podcasts_post_type', 0 );

This portion of code may look complicated but it really isn’t. You’re just inserting a bunch of options for the custom post type, and specifying what it will support. Note that:

  • The $labels array tells WordPress how to display the post type in the admin panel.
  • The $args array loads all the configuration from $labels array, and specifies the options for the custom post type.
  • The magic happens when the register_post_type( ‘podcasts’, $args ) function is called within the main podcasts_post_type() function with 2 arguments: the name of the custom post type and the options stored in $args (which is an associative array). Then, we just hook the podcasts_post_type() function to init, and let WordPress load it.

When you click save, and you upload the modified functions.php to your theme’s folder, you should see Podcasts (just bellow posts, because we set the menu_position in $args to 5) on your WordPress admin panel. If you hover it, you should see actions like “All Podcasts” and “Add New Podcast” — just as we specified in the $labels array. Since we didn’t insert any custom fields, when you try to add a new podcast, everything will be the same as if you were adding an ordinary post.

If you did notice, in the $args array, we added ‘podcasts’ as a taxonomy. We haven’t created this taxonomy yet, but this is ultimately going to hold our custom categories like Podcasts Categories, Podcast Shows, etc.

When it comes to WordPress custom post types, this is really all you need to now. Now the question becomes, how to display content from your CPT, how to create taxonomies (in our case, the podcast taxonomy), and how to create custom fields? Don’t worry, we are going to cover all of these, step by step!

The post WordPress Custom Post Types – Beginner’s Guide appeared first on SecondLineThemes.

]]>
WordPress Templates and the WordPress is_() Function https://secondlinethemes.com/wordpress-is-function-templates/ Tue, 03 Jan 2017 13:14:43 +0000 http://secondlinethemes.com/?p=238 The WordPress is_() function is a series of template functions tells you which type of page is being requested. For example, is_single() refers to a single post. Is_home() if the home page is being requested. Here is a list of the WordPress is_() functions and the requests they represent. The different WordPress is_() Functions Is_home() […]

The post WordPress Templates and the WordPress is_() Function appeared first on SecondLineThemes.

]]>
The WordPress is_() function is a series of template functions tells you which type of page is being requested. For example, is_single() refers to a single post. Is_home() if the home page is being requested. Here is a list of the WordPress is_() functions and the requests they represent.

The different WordPress is_() Functions

Is_home() –The front page

Is_single()- A single post

Is_page()- A static or a standalone page

Is_author()- An author

Is_date()- A year,month, or day

Is_year()- A year

Is_month()-A month

Is_day() A day

Is_time() An hour, minute, or second; either

Is_archive()- A category, an author or a date

Is_search()- A search

Is_404()- A 404 page

Is_feed()- A syndication feed

The is_page(), is_single() and is_category() can accept an id, name or nickname. Using the is_page();

Is_category() if a caegory is being served

Is_category(2) if the category with the id of 2 is being served

Is_category(About Me) if the category is ‘About Me’

Is_category(about-me) if the category is nicknamed about me

Using the is_() Functions.

We can use the WordPress is_() functions to customize our templates for different query types. For example, One index.php template can provide a different look for each WordPress is_() function. You can easily use the WordPress is_() functions to form conditionals for the various request types and generate whatever markup you like for each of those conditionals.

However, do not overuse too many conditionals as they tend to make the template rather busy and stressful to read. Alternatively, we can use multiple templates instead of just one template. For example, if we diosplay a single post page and a file named single.php is present, this will be loaded instead of the index. This goes for a category, author, pages etcetera. If is_page() is true and page.php is present , page.php is loaded. For each WordPress is_() function, strip the ‘is_’ from the front and add “.php” to derive the name of the template that will be loaded if that WordPress is_() function evaluates to correct. You can provide as many templates as you may wish or can also revert to using index.php.

The WordPress is_() function and the query-to-template mapping provide control for template and theme designers over presentation whether it is through one template or multiple templates.

The post WordPress Templates and the WordPress is_() Function appeared first on SecondLineThemes.

]]>