Add Facebook Open Graph Tags To WordPress

Facebook Shop

When a link is shared on Facebook it will be crawled to get the page title and description. The way Facebook will get this information is to search for Open Graph tags, these are meta tags added to your page with a title, description and image data. This data is then used to populate the Facebook status box when someone shares your link.

Add the following to your head tag so that Facebook will understand the content you are posting.

Page Title

To tell Facebook what the title of the page is you need to use the meta tag og:title, this will appear at the top of the post on Facebook.

<meta property="og:title" content="" />

Page Type

As you can post lots of different type of content to Facebook includes, articles, activities, businesses, groups, people, places..etc you can use the type meta tag to tell Facebook what type of content this is.

List Of Content Types

<meta property="og:type" content="" />

Post Image

You can set an image to use as the post image on Facebook by using the image meta tag.

<meta property="og:image" content="" />

Post URL

To set the URL for the shared link. This will be the link that will be placed on Facebook when your content is shared.

<meta property="og:url" content="" />

Post Description

Along with a default title and image you can set a small description of the content.

<meta property="og:description" content="" />

Site Name

Provide Facebook with your website name which can be referenced in your post on Facebook.

<meta property="og:site_name" content="<?php echo get_bloginfo('name'); ?/>" />

WordPress doesn't come with the functionality to add Facebook open graph meta tags, but you can use the below snippet to add open graph meta tags to all your posts.
Continue reading »

Block WordPress Admin By IP

WordPress security is a massive problem, because of WordPress being such a popular blogging platform it is used by millions of sites around the world. If someone is able to get access to your Admin area then they will be able to do anything on your site including deleting posts, changing passwords or shutting down your entire site.

It's always essential that you do as much as you can to tighten up security to your admin area.

Here is example of using htaccess which will block access to your admin area by anyone which is not using a certain IP address.
Continue reading »

Use jQuery To Highlight Active Menu Item

If you are using menus on your web designs it's a common web design technique to highlight the current page that you are on to show you where you are on the site.

This technique is normally done by adding a CSS class to the menu item to highlight it differently to the other menu items.

If your using a WordPress site then you are most likely using the WordPress function wp_nav_menu() to display the menu items. In wordpress this function will automatically add a CSS class of current_page_item to the current page.
Continue reading »

Add An Edit Link On WordPress Posts

On my WordPress themes I always link to have an edit link at the top of the posts by the title so that if I spot a mistake with the post I can easily edit it quickly.

Here is a WordPress snippet to use which will add an Edit this link at the top of your page. It will only be visible to the admin user and will take them directly to the edit post page.

This uses the WordPress function edit_post_link(), it must be used inside the_loop.

Just place the following in your theme where you want the edit link to appear.
Continue reading »

Disable All WordPress Plugins

There are some times in WordPress development when you need to disable all WordPress plugins to proceed with your development.

An example of this is setting up a multisite blog network on one WordPress install.

Here is a MySQL snippet for your wordpress database to disable all WordPress plugins at once.
Continue reading »

WordPress Blog Info Function

If you are a WordPress theme/plugin developer then there will be times when you need to get information about the current blog such as blog title or blog url. Using this function you will be able to get to many of the details supplied in the general settings menu of the WordPress dashboard.

The WordPress function you will use is.

bloginfo( $data );

Continue reading »