Absolute Center Images With CSS

Updated: in CSS

Here is a technique about how you can absolute center position an element on the horizontal and vertical in CSS.

Center Images Horizontally

To center something on the horizontal in CSS it's quite easy all you need to do is set the width on the element and apply an auto margin-left and margin-right on to the image. The browser will work out the exact margin on both the right and left side of the image. This will position the image in the center of the parent element just by using the width and the margin properties.

<img src="example.html" alt="Center Images" />

img {
     width:250px;
     margin: 0 auto;
}

Continue reading »

Check A Credit Card Number Passes Luhn Check

Updated: in PHP

When you accept credit card numbers on your website you need to do a number of different validation checks on the credit card numbers the user enters. When the form is submitted you will need to check that the user has filled out the correct credit card number, expiry date and security code number. Before you send this to the bank or payment gateway for them to validate and process you can do a couple of basic checks to make sure your not sending them poor data.

For example you can check if the expiry date is not empty and is in the correct format of mm/yy, you can check that the security code number is 3 digits and check that the credit card number is 16 digits long.
Continue reading »

Create A Page Template For Logged In Users

Updated: in Wordpress

There are times that you would want a page only to be accessible for users which have logged into your the WordPress user manager. Such as if you have a members only area of your website which is only for logged in users, you need to make sure that the page can not be seen by any users who haven't logged in yet.

WordPress has an inbuilt feature that allows you to easily manage users and roles for these users. Using the WordPress user manager you can define different roles to your users but they will all be able to log into WordPress and it doesn't matter which role they are assigned to.

As you are using the built in WordPress user manager then you can use a WordPress functions to check if a user is logged in or not.

This WordPress function is called is_user_logged_in(). This function will return a true or false on if the user is currently logged in and works just like the code below.
Continue reading »

Move Wp-Content Folder To Different Location

Updated: in Wordpress

Ever since WordPress version 2.6 you can actually move your wp-content directory to a different location. The wp-content directory will store all your theme files, plugin files and images.

Why Move The wp-content Folder

The best reason to move the wp-content is for security if you move this to an unexpected location any hackers looking to target this area won't be able to find it, or it will make it more difficult to find.

To change the location of the wp-content is quite simple as the location of this folder can be configured in your wp-config.php file.

All you have to do is add a new variable WP_CONTENT_DIR and change the location of your wp-content folder.

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/content/wp-content' );

To change the location of the wp-content URL there is another variable you can define in the wp-config.

define( 'WP_CONTENT_URL', 'http://www.paulund.co.uk/blog/content/wp-content' );

Continue reading »

Add Telephone Number Links With HTML5

Updated: in HTML5

Normally telephone numbers are adding to web pages as just static text of digits which doesn't offer any interaction to your visitors. With more and more people using the internet on their mobile it's time to change your telephone numbers to clickable areas to call the number directly from your mobile phone.

On your phone if you want to call a number of a web page you would have to copy and paste the number into your phone to dial it.

With this new features you can make telephone numbers links to dial just like you can with emails.

To allow your visitors to directly email you from a web page you place a link on the page and use the mailto: in the href.

<a href="mailto:example@example.com">Example Email</a>

Continue reading »

Get The Current File Used By Theme

Updated: in Wordpress

Sometimes in WordPress development you will need to display certain theme files, using the rewrite engine. For example using custom post types will use a file name single-{posttype}.php, but if you are having rewrite problems WordPress might just be displaying the single.php file.

If you have multiple post types which using similar styling it can be quite confusing on which theme file WordPress is actually using.

Add the below snippet into your functions.php file and it will return the current theme file WordPress is using.
Continue reading »

How To Remove WordPress Post Meta Boxes

Updated: in Wordpress

On the WordPress post screen there are a number of meta boxes which give you options to attach to the post.

For example you can change:

  • Categories
  • Tags
  • Featured Images
  • Excerpt
  • Trackbacks
  • Custom Fields
  • Discussion
  • Slug
  • Author
  • Revisions

If you have a multiple authors on your blog then you might want to disable some of the post meta boxes to anyone other the administrator.

For example you wouldn't want a guest author to disallow the comments or trackbacks on the article, this should be up to the administrators of the site.

To remove a meta box there is a WordPress function remove_meta_box().
Continue reading »

Add rel=”nofollow” To WordPress Comment Reply Links

Updated: in Wordpress

When using WordPress comments you can easily reply to a comment directly on the page by clicking on a reply link which will be positioned next to the comment.

Comment Reply Link Function

To add the comment reply link to the comment you need to use the WordPress function comment_reply_link().

If the Javascript file comment-reply.js is loaded on the page then the comment form will be moved just below the comment.
Continue reading »

Display Code Snippets In WordPress

Updated: in Wordpress

If you want to talk about programming or development in your WordPress post then there will be times when you want to write about code but make sure that the code doesn't behave like code would normally do in a web page. But you would still want the code to look just like it would look in a normal editor.

It is also important for any of your visitors to be able to copy and paste your code into their own application.

How WordPress Editor Handles Code

It depends on what text editor type in WordPress you use but you will have to do different things. If you use the Visual editor then WordPress will automatically convert characters like > and < into the HTML format &l t; and &g t;.
Continue reading »