Essential WordPress Snippets
As much as we’d like to think that every WordPress theme should come with a specific set of features, it usually doesn’t. What happens when your theme doesn’t have a feature you want? You just drop it in yourself, using these .
Template Directory
<?php bloginfo(
'template_directory'
); ?>
The Permalink
<?php the_permalink(); ?>
Include (in WordPress)
<?php
include
(TEMPLATEPATH .
'/filename.php'
); ?>
Dynamic Sidebars
WordPress makes it easy to drop a sidebar wherever you want. This makes it super-easy to customize your theme and add widgets wherever you want them. To enable a sidebar, you have to register in it your functions.php file.
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?><?php endif; ?>
<?php
if
(function_exists(
'register_sidebar'
) )
register_sidebar(
array
(
'before_widget'
=>
'<div>'
,
'after_widget'
=>
'</div>'
,
'before_title'
=>
'<h2>'
,
'after_title'
=>
'</h2>'
,
))
;
?>
Include jQuery in Your WordPress Theme
<?php wp_enqueue_script("jquery"); ?>
Add Google Analytics to Your Theme
Google Analytics is important for tracking your stats, visitors, and breaking down traffic. However, having to add the code to your theme each time leaves you wide open to forgetting, causing you to lose track of all your stats. Add this to your functions to avoid this problem in the future.
<?php add_action('wp_footer', 'ga'); function ga() { ?> // Paste your Google Analytics code here <?php } ?>
I have been using a thema called Dualshock and when I upload it to the host called fatcow, I got blank page by following error register_sidebar_widget is deprecated since version 2.8! Use wp_register_sidebar_widget() instead. how to solve this issues based on your experiences, thanks alot
John, are you sure you’re using the most recent version of the theme? I used dual shock for web design blog for a few months away after 2.8, and I never received any message like this one. You might want to contact my theme shop, and let them know about the issue. They may have a workaround that will solve the problem for you. If you make them aware of the problem, they could fix it for everyone with a patch in the next version. They are constantly updating and revamping their themes, so letting them know about issues enable them to make the best themes possible. Otherwise, John, I would have to look at the PHP of your theme to try to solve the problem. My best guess is that you will find this code in the functions.php file. Go to the theme editor, and do a search for register_sidebar_widget and it’ll take you right to it. From here, you may be able to replace the function with the latest sidebar PHP code. I hope this helps. If you need any further assistance all try to help you as best as I can.