All posts by dz42

WordPress Plugin API Hooks

Goes in the element of a theme, in header.php. Example plugin use: add JavaScript code.

Goes in footer.php, just before the closing tag. Example plugin use: insert PHP code that needs to run after everything else, at the bottom of the footer. Very commonly used to insert web statistics code, such as Google Analytics.

Typically goes in the Meta section of a Theme’s menu or sidebar; sidebar.php template. Example plugin use: include a rotating advertisement or a tag cloud.

Goes in comments.php directly before the file’s closing tag. Example plugin use: display a comment preview.

Echo Current Year in Copyright

When adding copyright information it is generally a good idea to render the copyright year dynamically. This can be done in many ways, here are 2 most common:

1st way

© 2012. – 2013.

© 2012. - 

2nd way

© 2012. – 2013.

© 

The second way is better when building new websites, since the output will automatically change next year from © 2013. to © 2013. – 2014. if $copyYear is set to 2013.

© 

WordPress head meta tags, scripts, links showing up inside body tag (Header appearing in body tag)

Sometimes in WordPress the header tags and links start appearing inside the body tag.


 
 
 
   "
    "
  meta tags and stylesheets
  the content
 

This problem generally occurs due to specific encoding of the file. We need to change the file encoding from UTF-8 to “UTF-8 without BOM” (BOM=”byte-order-mark”) and save it again. We can use Notepad++ as it allows us to specify the encoding we want to save the file in.

To change the default encoding for new and/or opened documents in Notepad++ go to Settings -> Preferences -> New Document/Default Directory and under encoding select “UTF-8 without BOM” and select “Apply to opened ANSI files” as well.

notepad-plus-plus-default-encoding