php

Alphabetized Glossary

php

October 07, 2020

Sort post content alphabetically, and divide each letter section with the appropriate letter.

Read More

The site health widget can alert you to issues on the website, but this can also be confusing to clients and increase maintenance requests to resolve “issues” when the website is functioning properly. Hide this widget using the following snippet.

Place in functions.php

add_action('wp_dashboard_setup', 'remove_site_health_dashboard_widget');
function remove_site_health_dashboard_widget()
{
    remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
}

Source.

Read More

Annual events (festivals, haunts, etc.) generally occur within the same month each year. Use this function to force update all of your calendar views so scheduled events are seen first without having to navigate through month / week views.

Read More

Simple function to check is WooCommerce Product is virtual. Can be used in the Cart or on Product page.

Read More

I use Page Links To a lot. Probably on every website I’ve built for the last five years.

Read More

Handy snippet for updating the default title text on a Comment Form.

Read More

I used this on a custom page template showing only Past Events.

Read More

I needed to query multiple post types and specific taxonomies and meta for a featured banner on a website, and found that using an array for post_type wasn’t working with the tax_query.

Read More

Disable Tabs

php

April 15, 2020

Remove Tabs from the sidebar, admin columns, and Post.

Read More

I’ve seen a lot of suggestions online to copy the Logout link shown in the WordPress backend into a Custom Link when using wp_nav_menu().

However, this will redirect users to the Logout Confirmation screen, and they will be prompted to logout once more.

Read More

This comes in handy if the ecommerce store does not ship any physical materials (e.g., downloadable, e-tickets, online classes, membership, etc).

Read More

I stumbled across this while creating a query of Custom Post data, where the content needed to be laid out in columns, and rows of equal height.

Read More

I really enjoyed customizing this. Check out more from the author of this snippet at the link below.

Read More

The below is used to check between two date fields and display only the items that fall within that parameter.

Read More

Style images differently according to weather the image is landscape, portrait, or even square.

Read More

This also works with Post Types created by Plugins.

Read More

Place the below in your functions.php to add your own custom font options to the core Paragraph Block.

Read More

Working with Gutenberg, I’ve learned how to build custom blocks to show content inline on a page, but I thought there could be an easier way that building a block, or a custom template.

Read More

To add a Custom Post Type to the Appearance > Menus section of the backend, add show_in_nav_menus => true to the Post Type args.

Read More

Building a custom website for a client or a friend, it might be easier to setup the site / brand colours as the defaults available in the Colour Settings dropdown.

Read More

Thank you so much to Chittaranjan for posting this on Stackexchange…

This function targets wp_nav_menu by it’s theme_location, and dynamically adds a Login / Logout button to it, including nonce.

Read More

Want to hide the editor from the WordPress editor because:

  • there are several users accessing the WordPress backend
  • a client has requested this feature be disabled
  • you never user it

Add the following line to wp-config.php above the “That’s it, happy blogging” comment line.

define('DISALLOW_FILE_EDIT', true );
Read More

I used this recently coupled with breadcrumbs to prevent certain items from showing on the top-most items in page hierarchy.

Read More

Works great if you’re using a sub-menu that shows related-level items when on a page.

Read More

Great to use on product pages to reveal varied standardized text from the template when Products use shared terms like colours, or sizes.

Read More

Displaying an image from an ACF custom field is slightly different on an Archive / Single page, versus on a page, or in a regular loop.

Read More

I’ve always wanted to apply automatic inherited styles to pages that are child pages of a custom template, and now I can!

Read More

Works in relationship with has_children();

Read More

I have used counting classes so many times, but never understood them to this extend until I found this example.

Read More

Spam and malware bots are being programmed smarter, and they can sometimes target email urls that are placed in the content area.

Read More

The following works in multiple languages and can be used inline:

Read More

The Post Object field in ACF grabs all Post Statuses in the WordPress backend, but does not provide filtering within the plugin’s interface to select only Published Post items.

Read More

Get Terms as Checkboxes

php

September 19, 2018

This makes working with filters so much easier.

Read More

I previously attempted this using post_parent, grandparent and ancestor information in an if statement, but I find this method is cleaner.

Read More

Have you ever wanted to create a layout that updates automatically based on the number of items shown?

Read More

Adjust your post feed according to which Posts are using Read More tags.

Read More

I use this fairly often. I find working with plugins I already have installed is better than installing additional plugins to resolve the issue I’m trying to accomplish more reliable.

Read More

I’ve always wondered how to do this, and now I have an example on hand that I can refer to in the future. Comes in handy if you’re using custom navigation / filters with categories or terms.

Read More

Turn your Gravity Form into a booking calculator!

Read More

If your website has several News / Blog contributors, you can display a list of Authors by role and link back to their individual landing pages (author.php).

Read More

Check if Page has Children

php

January 24, 2018

Use the following function to determine if the current page you are on has any child pages. 

Read More

WordPress has so many different “stock” template types that are not used on every type of website. For example, a small business website, may not use the Archive, Blog or Single page layouts.

In my seven years of building WordPress website, I have yet to come across a single client that uses the “Attachment Page” layout (properly, at least).

Read More

Working on heavily cached servers with limited access to cPanel / server resources makes it difficult to apply website updates in a timely fashion.

Read More

A handy snippet that can be used in conjunction with Advanced Custom Fields as well as the WordPress default custom fields to remove Posts, Pages and Custom Post Types from feeds.

Read More

If you have transitioning content on your website, such as a Templated Page that will be launching at a certain date or time, you can setup a custom countdown landing container, and use a custom field to automatically update the content at a scheduled date and time.

Read More

On the category archive, or the single post page, use the following loop to retrieve the name, slug or ID of the top most category to use as a header, or link.

Read More

Building custom menus and filters is unavoidable. If you’re not comfortable triggering the active item with jQuery to add an active class, you can find the current page ID, and use existing WordPress CSS classes to reapply styles already within your stylesheet.

Read More

Enable background and text colour changes within your template using Advanced Custom fields.

Read More

I work with Gravity Forms, and Gravity Forms User Registration a lot, so being able to redirect users to a custom template instead of a front end user profile (such as Theme My Login) would be preferred.

With Gravity Forms, I’m able to enable custom notifications based on the fields that are updated.

Read More

If you’ve built a custom Registration Page with a form that is gathering all of your customer’s information, the default WordPress Register link, has become null and void.

Read More

I recently worked in a website that had multiple skins within a single domain. The different themes were controlled and activated by their related parent pages. I’ve already gone over how to add an ancestor class to the body, but I needed to add a couple additional features to this website as well.

Read More
<?php $tax_slug = get_query_var( 'taxonomy_category' ); ?>

Comes in handy if you’re working with custom post types, or external plugin archive pages.

Read More

Use with Link to Top-most Page in Hierarchy for a more dynamic nested sub-navigation menu.

Read More

Change the default number of words returned by the_excerpt() using this function:

Read More

A deep number of page levels in a website can make navigation difficult for front end users. In addition to breadcrumbs, it is worthwhile to maintain your Top-Most Page Title in all areas to help your visitors find their way between the hierarchical sections of your site.

Read More

Get_terms does not natively support exclude children. Here is a function that you can use to help keep your front end organized, and structured.

Read More

More often than not, content is added to a website for aesthetic purposes (carousels, widgets, call to action buttons, etc.), not necessarily to provide information.

Read More

Setup page titles for different page levels using the following statement. Below example is using the Thematic WordPress Theme.

Read More

The All in One Event Calendar by Time.ly is extremely flexible if you need to place several widgets and event shortcodes on your website.

Using the Plugin to generate your own custom query and feeds of your Event information is not very intuitive, and finding valid information a long process.

Read More

Similar to my Subnavigation Function, this will display widgets and adjust column widths if widgets are active on the page.

Read More

This is a continued modification of my earlier post for toggling multiple embedded YouTube videos into a larger playing div.

Since I was already using Posts to embed the videos, enabling a Featured Image for a Poster, and using the Content editor for a text overlay was a simple feat to accomplish.

Read More

Template layouts (and client requests) will often require a list of categories to be laid out in a specific order to draw attention to different content.

Read More

The Advanced Custom Field plugin’s Taxonomy field type has been giving me a hard time for several hours now … This plugin is so versatile, that there is simply not enough documentation on the website, despite all of the amazing work done by Elliot Condon.

Read More

Sometimes when building arrays for directories, or archives, we have to list all of the content (even the empty ones).

In the unfortunate circumstance when you have no choice but to use the foreach loop, here is a handy workaround to check if the loop is empty, and display a custom message

Read More

You can achieve more stylistic versatility within your WordPress backend, and theme, if you’re able to inject fonts within the WYSIWYG editor.

This is possible if you are using embedded fonts, or if you are using fonts from a hosted library using the below function, and the Advanced TinyMCE plugin addon.

Read More

Add Class to Elements by Count

php

September 22, 2016

Creating dynamic layouts can make it easier on your clients (and yourself) to update your content without worrying about checking the front end to make sure the selections are correct, or having to update various posts / content areas following updating new content.

The following example shows how to add a colour class to your container using the_loop, php and with some CSS adjustments, possibilities are endless!

Read More

Discovered this handy cheat-function over here and it was just what I have been looking for to help me add further customization to all the Custom Post Types that are created by Plugins upon installation.

Read More

Great way to hide categories from the front end if they are reserved for a different purpose:

Read More

Sometimes it’s necessary to further customize archived data into sortable sections (organized by date, like below, or category), so it’s easier for visitors to find what they’re looking for at-a-glance.

Read More

If Is User by ID

php

June 07, 2016

Found this demonstrative function in the wp_get_current_user(); WordPress documentation, as a way to test if a user is logged in

Read More

Useful way to grab the title from the page ancestor, and setup child page titles.

Read More

This example will allow for a class to be added to the current child page so it can be custom styled.

Read More

Sourced here, this will help filter content posted by multiple users on a blog.

Read More

Add or replace the contents of searchform.php with the following in order to enable a dynamic search field with an image search icon

Read More

Drilling down across multiple post types can help enhance relationships between the content on your website, and direct the flow of traffic on your website.

Read More

A useful addendum to queries when multiple products / post types are going to be featured with the same / similar names. This will prevent the need to add alphanumeric differential identifiers to the titles, and the links, slugs or categories assigned to the content can be used to divide up the information accordingly.

Read More

Sort Posts by Category

php

February 16, 2016

When generating archive pages, it’s sometimes necessary to return all of the Posts (for a given Post Type), sorted by the Category for visitors to sort through easily.

Read More

Sourced here, this snippet can be inserted within single.php and used to isolate the previous and next navigation links when working with Custom Post Types that have multiple Taxonomies and Terms to allow for more streamlined navigation:

Read More

Use if statement found here that allows you to sort by the parent category, to show only relevant child categories on various landing pages:

Read More

Inherit Featured Image

php

December 10, 2015

If you’d like to continue using the_post_thumbnail in your theme, but do not want to use a fixed default, use this snippet to inherit images from parent pages.

Read More

Handy when listing date / event oriented posts on a feed. Sourced here.

Read More

Generate a list of WordPress posts, grouped by month, for the specified author.

This comes in handy when working with multiple authors, and needing to generate a list of archives for their content.

Read More

Stumbled across this bit of code here. Used to show the main navigation in a sidebar for all child and grandchild pages.

Read More

Alternative: echo wpautop(get_field(‘featured_summary’));

Read More

Single Post as Home Page

php

November 03, 2015

Add the following code to your functions.php in order to redirect your home.php template to the most recent single post

Read More

Adding Counters

php

October 08, 2015

Adding increasing increments to loops can help with styling elements, and revealing additional content. Here are few examples to implement counters with php.

Read More

An alternative to wp_list_categories() – using get_categories() with a loop can prove to be quite useful in terms of customizing category displays.

Read More

Sometimes transitional content is used in one area of a website, like to display hours in a Header or Sidebar. Instead of having the client (or yourself!) update this content every day, get your code to update it for you when the weekdays change.

Read More

Use this to grab the Featured Image from the post parent if the child page is not using a Feature Image.

Read More

I have dug all over the internet for a query like this one!

This will generate the get_archives_link needed to link to your Custom Post Type year/month url.

Read More

Drop the below if statement within a loop and add a count for each colour change that you need with the template.

This is a great example to reference if you’re building a scrolling website, and loading all pages in a single progression with alternating templates applied.

Read More

Follow this WordPress Codex example and this support forum comment, add this into your header.php file and style the resulting body class accordingly

Read More

Get Category by Name

php

June 26, 2015

Retrieve the ID of the first item in a loop:

$category = get_the_category(); 
echo $category[0]->cat_name;
Read More

For use with older browser version testing.

Read More

Create a menu that drills down to subpages as they exist.

Read More
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.