Remove columns from the WordPress Admin posts screen

When building WordPress websites something that I’m asked more and more frequently is whether its possible to hide or remove columns from the posts, pages and custom posts admin screens. The most common requests are to remove the comments column because that particular site doesn’t have comments, or if there is only one author for the website that column may not be needed.

By using the following snippet of code we can do that very easily.


function remove_comments_column( $columns ) {
unset($columns['comments']);
return $columns;
}

function remove_column_init() {
add_filter( 'manage_posts_columns' , 'remove_comments_column' );

}
add_action( 'admin_init' , 'remove_column_init' );

To remove a different column, for example: Author, all we need to do is change line 2 to

unset($columns['author']); 

instead.

Simples 🙂

HeroThemes Tutorial: Integrating Heroic Knowledge Base with WooCommerce

Introducing my next article for HeroThemes. This article has taken what was covered in the first article and moved forward to take a look at how the Heroic Knowledge Base plugin could be integrated with WooCommerce to create Frequently Asked Questions for each product. Something that’s always useful! 🙂

Although the subject is about integrating the KnowledgeBase plugin the focus of the article is on how to integrate content into WooCommerce and therefore could be used in lots of different scenarios. Techniques covered include

  • Using Advanced Custom Fields to select content to display on product pages
  • Looking at the WooCommerce templating system,
  • How to add the selected content to templates,
  • Adding the selected content using and hooks and filters instead.

final-faqs-672x532The end result of the article is creating a new tab on each product page that includes your custom content.

This article is quite in depth, and covers a lot of information and therefore assumes a good knowledge of WordPress, theme development and especially knowledge hooks and filters.

I hope you find it useful! 🙂

The full post can be read here: Integrating the Heroic KnowledgeBase Plugin with WooCommerce

The code for the tutorials can be found on Github here.

HeroThemes Tutorial: Using the KnowledgeBase templating system & theme integration

12519504_1700939276854972_1662585904_nI’m really pleased to be able to share with you my first tutorial for HeroThemes on how to customise their Knowledge Base plugin and deep theme integration. The article is aimed at theme developers with a knowledge of PHP and covers how to use the templating system to allow the plugin to integrate seamlessly with your theme and let you make some advance customisations to it.

Using the newly released TwentySixteen theme as the base, the article goes into detail on how to set up the Knowledge BAse plugin, some of the settings available out of the box, how to include templates in your theme so that you can modify the layouts, and how to apply styling to those files.

The full article can be read here: http://herothemes.com/blog/heroic-knowledge-base-using-templating-system/

This is the first in a series of articles I will be writing for HeroThemes over the coming months, so keep your eye out for the next one and I hope you like it! 🙂

The code for the tutorials can be found on Github here.

Display only one price for grouped products – WooCommerce

This is a handy little function to control what price is displayed for a range of products that have been grouped in WooCommerce. Often the grouped products all have different prices and by default WooCommerce will display a range such as £50 – 1000. Which is not ideal. This function allows you to display the maximum price.

/**
* Returns max price for grouped products
**/
function wc_grouped_price_html( $price, $product ) {
$all_prices = array();

foreach ( $product->get_children() as $child_id ) {
$all_prices[] = get_post_meta( $child_id, ‘_price’, true );
}

if ( ! empty( $all_prices ) ) {
$max_price = max( $all_prices );
} else {
$max_price = ”;
}

$price = ‘<span class=”from”>’ . _x(‘From:’, ‘max_price’, ‘woocommerce’) . ‘ </span>’ . woocommerce_price( $max_price );

return $price;
}
add_filter( ‘woocommerce_grouped_price_html’, ‘wc_grouped_price_html’, 10, 2 );

NB: This is not originally my code, but unfortunately I can no longer find the website that published it to reference it correctly.