Categories
Wordpress

Personalise the WordPress maintenance page

Every time you update your WordPress site, the website will show the maintenance message to visitors.

Unfortunately the default maintenance page is not so pretty. What can you do about that?

Simple! Just design an HTML page as you like with the message that the website is under maintenance and it will come back soon.

Use the file name

maintenance.php

for this page and upload it to your

/wp-content/

folder.

The next time you will update your WordPress installation that page will be served to your visitors.

 

Categories
Security Wordpress

Protect your wp-config.php

You can protect your wp-config.php in WordPress if you have access and your server support .htaccess.

Just make a little addition to your .htaccess as following:

<File wp-config.php>
order allow, deny
deny from all
</File>

Malicious people will have an harder life in order to get hold of your wp-config.php file, which contains really sensitive information.

Try this out on a test installation first just to avoid funny surprises in case you have some sort of special configuration.

Categories
Security Wordpress

How to show a custom post type in a category page in WordPress

If you want to use the default taxonomy category in a custom post type (i.e. products) it is easy, just create your new post type “Product” and link it to use the taxonomy category.

Example
add to your theme function.php the following:

add_action('init', 'create_my_post_types');
function create_my_post_types() {
	register_post_type(
		'products',
		array(
			'label' => 'Products',
			'description' => '',
			'public' => true,
			'show_ui' => true,
			'show_in_menu' => true,
			'capability_type' => 'post',
			'hierarchical' => false,
			'rewrite' => array('slug' => '', 'with_front' => true),
			'query_var' => true,
			'supports' => array(
				'title',
				'editor',
				'excerpt',
				'trackbacks',
				'custom-fields',
				'comments',
				'revisions',
				'thumbnail',
				'author',
				'page-attributes'
			),
			'taxonomies' => array('category'),
			'labels' => array (
				'name' => 'Products',
				'singular_name' => 'Product',
				'menu_name' => 'Products',
				'add_new' => 'Add Product',
				'add_new_item' => 'Add New Product',
				'edit' => 'Edit',
				'edit_item' => 'Edit Product',
				'new_item' => 'New Product',
				'view' => 'View Product',
				'view_item' => 'View Product',
				'search_items' => 'Search Products',
				'not_found' => 'No Products Found',
				'not_found_in_trash' => 'No Products Found in Trash',
				'parent' => 'Parent Product'
			)
		)
	);
}

As alternative to create you post type you can easily use a WordPress plugin Custom Post Type UI or similar plugins.

Soon you will realise that when you go in a category page just default post will be displayed. Where are my products gone?

Strangely if you use the widget Categories with the tick “Show post counts” on you will see that the total number of post in a single category will be the sum of the default posts + the products (custom post type)

In order to have in the category page both the post types together you need to patch a bit the query that return the post inside a category.

Add to your theme function.php the following:

add_filter('pre_get_posts', 'my_get_posts');
function my_get_posts($query) {
    if(is_category() && false == $query->query_vars['suppress_filters'])
        $query->set('post_type', array('post', 'products'));
    return $query;
}