How-to fix the hReview snippet for GD Star Ratings

Recently it becomes much easier to get your rating into the search results of Google. Using hReview rich snippet code in your blog post can raise the CTR in Google if the rating is visible. The GD Star Ratings plugin has already a function to show the snippet beside the stars widget, but the markup is according the Google Webmaster Help section not valid. We wrote a small function that will fix this problem.

Continue reading How-to fix the hReview snippet for GD Star Ratings

Remove HTML comments in WordPress

If you check the HTML source from your WordPress website, you will notice a lot of HTML comments. These comments are not visible for visitor and can help the WordPress theme developer while working on his HTML code. Some of you would say: “debugging information shouldn’t be visible to the client”.
There are also plugin developers which place this kind of comments into the code to “mark” their work.

The following WordPress actions are able to filter your code from all HTML comments. Place the PHP code into your functions.php file inside the WordPress theme directory.

function callback($buffer) {
    $buffer = preg_replace('/<!--(.|s)*?-->/', '', $buffer);
    return $buffer;
function buffer_start() {
function buffer_end() {
add_action('get_header', 'buffer_start');
add_action('wp_footer', 'buffer_end');

This kind of output buffering is more memory intensive and might raise your server’s load. Use always a WordPress cache plugin.

Show WordPress comments by category only

Recently I needed a widget or plugin which is able to show only the comments from th current category. It seems that this kind of widget is not very common, so I checked the code from several themes I used in the past and also some plugin. The function below should do the trick, place this function into your functions.php file (theme directory) and add the function into your sidebar.

Features included:

  • Shortened comments snippet
  • the comment author’s name
  • filter by one or more category IDs
  • shorten the post title if needed
  • Show the comment date (local date format)

Inside this function another custom function is called, include that function too:

How-to use the current category ID inside that function?

$myCategory = get_the_category();
$catId = array($myCategory[0]->cat_ID);
echo my_recent_comments(10, 100, $catId);

The SQL statement inside the comment function is based on a plugin I found on the WordPress website.

Parent pages filter function your WordPress admin section

If your WordPress Blog has a lot of pages (not posts) it becomes very hard to select them in the  pages list (WordPress back-end). A select menu with all the parent (top) pages would be a great and useful filter function (like the categories filter in the posts section).

Check this comment for a modified function which is able to filter grouped products in WooCommerce.

The function below will add the select menu with the parent pages as a filter:

function fws_admin_posts_filter( $query ) {
    global $pagenow;
    if ( is_admin() && $pagenow == 'edit.php' && !empty($_GET['my_parent_pages'])) {
        $query->query_vars['post_parent'] = $_GET['my_parent_pages'];
add_filter( 'parse_query', 'fws_admin_posts_filter' );

function admin_page_filter_parentpages() {
    global $wpdb;
    if (isset($_GET['post_type']) && $_GET['post_type'] == 'page') {
		$sql = "SELECT ID, post_title FROM ".$wpdb->posts." WHERE post_type = 'page' AND post_parent = 0 AND post_status = 'publish' ORDER BY post_title";
		$parent_pages = $wpdb->get_results($sql, OBJECT_K);
		$select = '
			<select name="my_parent_pages">
				<option value="">Parent Pages</option>';
		$current = isset($_GET['my_parent_pages']) ? $_GET['my_parent_pages'] : '';
		foreach ($parent_pages as $page) {
			$select .= sprintf('
				<option value="%s"%s>%s</option>', $page->ID, $page->ID == $current ? ' selected="selected"' : '', $page->post_title);
		$select .= '
		echo $select;
	} else {
add_action( 'restrict_manage_posts', 'admin_page_filter_parentpages' );

How-to use this PHP code

Open the file named “functions.php” which is inside your themes directory and copy the code into this file and re-visit the pages section.

This function as based on some code I found at WP-Snippets.

Tip! If you need more or better filter options, try Admin Columns. You need to buy the PRO version to use all features, but it’s worth any penny!