Password Protect more than just Content and Comments

The following is not a news, but today I had to fix a problem like that at work, so I thought that can be repeated for who has a similar situation.

worpress-password-protected

In WordPress when you use Password protected posts or pages, the post or page content will be hidden until the user inserts the password.

By default WordPress will hide the content and the comments of the post or page that  uses Password protected in the settings and show on screen a message like

This post is password protected. To view it please enter your password below:

The title will also start with “Protected: “. See here how to remove the title prefix.

When the user will type the right password than will be able to view the page completely.

Code wise will be hidden just the text or HTML returning by the following methods

the_content();
comments_template();

inside the files in your WordPress theme (page.php or single.php or index.php).

Problem?

You will find that if you use custom fields or simply use in your loop

<img scr="<?php echo get_post_meta($post->ID, 'postThumb', true); ?>" />

those data will not be protected and they will be visible on the screen.

How to protect custom fields in WordPress?

The simple solution is to use the WordPress function post_password_required() like in the example below

<?php
    if ( !post_password_required() ) 
    { 
        // your protected stuff here
    ?>
    <img scr="<?php echo get_post_meta($post->ID, 'postThumb', true); ?>" />
    <?php
    }
?>

Remove Protected and Private title prefix

If you use Private or Password Protected posts or pages you might want to remove that awful title prefix

  • Private: …
  • Protected: …

To remove the title prefix you can simply add in your WordPress theme functions.php file, the following code

function the_title_trim($title)
{
  $pattern[0] = '/'.__('Protected').': /';
  $pattern[1] = '/'.__('Private').': /';
  $replacement[0] = ''; 
  $replacement[1] = ''; 
  return preg_replace($pattern, $replacement, $title);
}
add_filter('the_title', 'the_title_trim');

This code will remove the title prefix for Private and Password Protected pages and posts, independently by the language used in the WordPress installation.

HiFi Cinema Webstore

Ecommerce website for HiFi Cinema. The  website is based on WooCommerce and it is super personalised.

The navigation bar will always remain at the top op the screen (just for large screens).

The design follows a fluid design just for computer screens and tables (horizontal orientation).

hifi-cinema-webstore-2013

 

hifi-cinema-webstore-2013-imac

 http://webstore.hificinema.co.uk/

Redirect to post when search query returns single result

To avoid the list of just a single search result, you can add the following code in your theme’s function.php file.

add_action('template_redirect', 'single_result');  
function single_result() {
	global $wp_query; 
	if ( is_search() && !is_paged() ) {
		if ( $wp_query->post_count == 1 ) {
			wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
		}
	}
}

This code will also avoid the automatic redirection in case of many search results split in pages and in the last page there is just a single result.

How to make a telephone number clickable on your Android or your iPhone

If you use your smart-phone (iPhone or Android) for surfing on internet you will have notice that some times is very frustrating or very difficult to copy and past a phone number in order to use it for a phone call.

A simple and quick solution for all the web designers/developers to avoid  to make the user  s life difficult is to set the telephone number as a link.

Please call <a href="tel:+441234567890">(+44) 0123 456 7890</a>

instead of

Please call (+44) 0123 456 7890

A link like that will not have any side effect for a normal desktop or laptop user but it will be very helpful users that use a smart-phone or a tablet.

So a good practice is to  always use this telephone number link

<a href="tel:+441234567890">0123 456 7890</a>

tel: is also compatible with some telephone softwares.