Functions are causing errors

You don’t want to add function vote_up() { [...] } at the top of every post if you display more than one post on a page. You want to declare the vote_up() function in your plugin’s PHP file.

Once the plugin declares the function, as long as the plugin is active, you can just call the function wherever you need it.

I would however suggest two further changes:

  • Prefix the function name.

vote_up is rather generic, and you run the risk of colliding with other plugins and/or themes. Something like [plugin_name]_vote_up() would work nicely.

  • Check to make sure the function exists before using it.

If you call vote_up anywhere outside the plugin (e.g. a theme template file), surround the call as follows:

if ( function_exists( 'vote_up' ) ) {
    vote_up();
}

This will ensure that your theme files will still function properly if you ever need/want to deactivate the plugin for some reason.