Tag: PHP

WordPress: Create a Custom Widget (Part 2)

| 4 comments

This entry is part of my WordPress development series, providing tutorials on specific things you can do in WordPress. Read some more?

In the second part of this tutorial, we are going to expand upon our basic custom widget we have already created by utilizing a simple form in the back-end. Unlike in the previous tutorial where each instance of the widget on our website displays the same, uneditable information, this widget will be able to have unique information for each instance of the widget placed throughout our website.

Read More »

WordPress: Create a Custom Widget (Part 1)

| 0 comments

This entry is part of my WordPress development series, providing tutorials on specific things you can do in WordPress. Read some more?

WordPress provides a lot of default Widgets that can be useful for displaying additional content in sidebars, footers, etc. But sometimes you may want to use a widget to display content that isn’t available in one of the default widgets, or you want to display the content in a different way. In Part 1 of this tutorial, I will show you how to create a basic custom widget, without any options, that you can use throughout your website to display whatever content you like!

Read More »

WordPress: Multiple Search Forms

| 4 comments

This entry is part of my WordPress development series, providing tutorials on specific things you can do in WordPress. Read some more?

Sometimes you may need to have multiple search forms within your website. You can easily call the WordPress function get_search_form() wherever you want your search forms to be. An example of this could be when you have a search input in the header or footer of your website. But then, you may have a search form at the top of your mobile navigation that slides out on mobile devices. Or, there’s one on the Search page of your website as well when there’s no results.

However, if you’re someone (like me) who tries to have valid code (or as close as we get), then this won’t work with the default WordPress search form because it will use the same ID for each one, which won’t validate.

Read More »

WordPress: Sortable Custom Columns

| 2 comments

This entry is part of my WordPress development series, providing tutorials on specific things you can do in WordPress. Read some more?

Continuing on from the previous tutorial where we added custom columns, we are now going to make these columns sortable like the regular default columns in WordPress (such as post/page title and publish date).

For simplicity, we will continue to work in our functions.php file. You can edit this file by going to Appearance > Editor in your WordPress admin panel, or using a text editor with FTP.

From the last tutorial, I have already created my custom columns for my custom post type “Cats”. So first we have to tell WordPress to make our columns sortable using the function add_filter().

// Make columns sortable
add_filter( 'manage_edit-cf_cats_sortable_columns', 'cats_sortable_cols' );

function cats_sortable_cols( $columns ) {

	$columns['age'] = 'age';
	$columns['toy'] = 'toy';

	return $columns;
}

Read More »

WordPress: Adding Custom Columns

| 0 comments

This entry is part of my WordPress development series, providing tutorials on specific things you can do in WordPress. Read some more?

This tutorial is going to show you how to take the metadata stored in your custom meta box (or boxes) from your custom post type and display it as columns on the browse or “All” page – for my custom post type, that would be the page “Cats”. This is a great way to show some extra information about your custom posts at once without having to go to each individual post. Continuing on from the previous tutorial, I am going to display the age and favourite toy metadata that I stored for my cat Azaezel.

For simplicity, we will continue to work in our functions.php file. You can edit this file by going to Appearance > Editor in your WordPress admin panel, or using a text editor with FTP.

To begin, we first have to create the columns. We do this by using the function add_filter().

Read More »