Category: Code

Yoast Breadcrumbs for Custom Post Types and Blog Posts

There are a couple tricky settings that affect how Yoast’s breadcrumbs display for Custom Post Types and Blog Posts. It can be a bit frustrating when breadcrumbs are not displaying correctly and you don’t know why. I figured out today, it’s all in the settings. Custom Post Types Breadcrumbs When…

Events Calendar tribe_get_events and timezones

Today I spent a frustratingly amount of time trying to list upcoming Events Calendar events on a website, and getting them to stay listed through the start and end time of the event. The reason why events were falling off early is because of the timezone. Events Calendar’s documentation (which…

Remove Post Tags from WordPress Admin

Remove from Posts sub menu in left side WordPress Admin Menu: function unbox_change_menus () { remove_submenu_page( ‘edit.php’, ‘edit-tags.php?taxonomy=post_tag’ ); } add_action(‘admin_menu’, ‘unbox_change_menus’); Remove Tags column from List of Posts in Admin: add_filter(‘manage_posts_columns’, ‘unbox_custom_columns_posts’); function unbox_custom_columns_posts( $defaults ) { unset($defaults[‘tags’]); //remove tags return $defaults; } Remove Tags Side Box when editing/creating…

Single Post Template Functions

Get the date – always prints date even if on second post on same day. $post_id is optional if inside of posts loop. See Formatting_Date_and_Time for $format value. <?php $date = get_the_date( $format, $post_id ); ?> does not print date if displaying second post on same day in loop. <?php the_date()…

Retrieve Pages by Path or Template in WordPress

By Template: $pages_using_template = get_pages(array( ‘meta_key’ => ‘_wp_page_template’, ‘meta_value’ => ‘template-press-release-list.php’, ‘post_status’ => ‘publish’, ‘post_type’ => ‘page’, ‘hierarchical’ => 0 //because page looking for could have a parent – without this only gets top level pages. )); Check if got anything and use it from query above: if($pages_using_template && count($pages_using_template)…

WordPress Menu Functions

wp_get_nav_menu_items( string $menu, array $args = array() ) Returns an array of menu items. $menu parameter is slug or id of Menu created in WordPress. $args is from here: get_posts, which isn’t very helpful for filtering what menu items you want to display.  This function returns an array that you…

Category Template Tags

The following functions can be used on the category.php template to display information about the current category. Display Current Category Title on category.php: <?php single_cat_title(); ?> <?php single_term_title(); // more generic – can be used on archive.php too ?> Display Current Category Description: <?php echo category_description(); ?> Get Current Category…

Handy WordPress Functions

A collection of WordPress functions I use often. Link to Home: <?php home_url( $path_relative_to_root, $opt_scheme_http_https ); ?> <?php echo esc_url( home_url( ‘/’ ) ); ?> Include another php file: get_template_part($slug, $name); *File name separated on ‘-‘ between two inputs to function. So if named include-content-blocks.php call is: get_template_part(‘include’, ‘content-blocks’); Custom…