SubscribeFunctions File
A theme can optionally use a functions file, which resides in the theme subdirectory and is named functions.php. This file basically acts like a plugin, and if it is present in the theme you are using, it is automatically loaded during WordPress initialization (both for admin pages and external pages). Suggested uses for this file:
* Define functions used in several template files of your theme
* Set up an admin screen, giving users options for colors, styles, and other aspects of your theme
The "Default" WordPress theme contains a functions.php file that defines functions and an admin screen, so you might want to use it as a model. Since functions.php basically functions as a plugin, the Plugins Resources list is the best place to go for more information on what you can do with this file.
function twitter_snippet() {
$html= <<<EOT
PASTE HTML HERE
Yadda, yadda, paste paste
EOT;
return $html;
}
$lt;?php print twitter_snippet(); ?>
function twitter_snippet() {
print <<<EOT
PASTE HTML HERE
Yadda, yadda, paste paste
EOT;
}
<?php twitter_snippet(); ?>
You are not logged in, either login or create an account to post comments
funtion my_function() {…stuff here…
}
This all assumes that the whole thing is bracketed in the normal <?php…?> wrapper.
If you wanted to be ably to insert a chunk of static HTML, you'd do something like this:
funtion my_function() {$output = "<p>Here's some HTML-formatted text!</p>";
echo $output;
}
This is pretty boring, of course. And unless you've got a plugin that will interpret php inside your blog entries, you can only use it in your templates, where you're better off just pasting the actual content in. And if you only want to add these snippets of text to your sidebar, you can just use WP's native widgets.
posted by adamrice at 10:53 AM on March 21