Header and Footer

Header and Footer WordPress Plug-in lets you to insert whatever you need in to the head and the footer parts of each blog page and before and after the content of posts.

Its main purpose is to add various scripts to track the access to the blog (such as Google Analytics code, the verification code required by Google Webmasters Tools, the Facebook script for the like button or the Twitter one or the Google one for the Google Plus 1 button).

To insert something you have only to copy and paste the code supply by th service you want to use, there is no need to install 5 different plug-ins to integrate 5 external services. Clearly, if you aren’t able to copy and paste following the specific service examples or if they are unclear, keep on using a specific plug-in.

The code to be added on head section or footer section can contain PHP script part as well that will be executed.

Code can be added before or after the posts so you can easily “inject” the AdSense or other advertising network code.

Was it useful to you? Don’t miss a +1 or a like, thank you!

User guide

I create a PDF file with a more complete Header and Footer user guide: it is still valid but not all the features are explained.

Header and Footer Plugin User Guide (2573)

Download

Header and Footer is available on WordPress Plugin Directory at this URL

http://wordpress.org/extend/plugins/header-footer/

and if you find it useful, don’t forget to give it a vote.

Quick list of features

(so you can decide to install or not)

  1. Add a custom code (Javascript, CSS, HTML) to the head (<head>) section of every blog web page (eg. Google Analytics, Facebook, …)
  2. Add custom code to the head section only on the home page (eg. Google Webmaster verification code)
  3. Add custom code on the footer (before the </body>) of each blog web page (eg. late loading third party script)
  4. Codes can contain PHP parts that will be executed to add injection logic (minimum programming skills needed)
  5. Add custom code before and after each post content
  6. Add custom code before and after each page content
  7. Optionally add the Facebook og:image tag so a like on a post will be shown with the thumbnail or first post image
  8. Configurable default image for og:image Facebook tag for posts without an image
  9. Facebook og:type tag for home and generic web pages
  10. bbPress compatibility: the og:image tag will be filled with the first forum (see the FAQ)

F.A.Q.

About bbPress and og:image Facebook tag: where have I to add the image?

Creating a forum is like creating a post. Add an image from the forum editing panel (even if without inserting it on the forum description) and that image will be used.

Does the plug-in generate the other og: Facebook tags (not mentioned above)?

Actually not.

What image is used for the og:image tag on home page?

If a default image is specified, that one.

I added PHP but it will be printed out than executed.

PHP must be add this way: <?php some code ?>. It can spans multiple lines.

Usage

All posts about Header and Footer can be found under the tag “header footer“.

It’s so simple that this paragraph is not really useful, but… here a screen shot of the configuration panel with values I’m using in a my blog.

header-footer-1

There are themes which fo not have the “wp_footer” call, or have the footer crypted: check the source of generated pages to see if the code you configured is injected or not. Other plugins that add such kind of codes in the footer may have the same problem!

The image below is the source of an internal page of a my blog: the Analytics code is there.

header-footer-2

Using PHP code

PHP code can be used on footer and header configuration to add specific logic and control what will be inserted. The classical example is to avoid Google Analytics code while the admin is logged in.

Here an example directly from my blog:

<? if (!is_user_logged_in()) { ?>
<script type="text/javascript">
...GOOGLE ANALYTICS CODE...
</script>
<? } ?>

The surrounding

<? if (!is_user_logged_in()) { ?>

and

<? } ?>

let the code to be added only when a user is not logged in. Clearly this logic is good only for blog which have only an administrator, not the ones having lot of registered people that has to be tracked.

Versions and more

Everithing I wrote about Header and Footer plugin can be found under the tag “header footer“.