WordPress 3 - functions.php Queries - wordpress

I'm new to WordPress theming and have downloaded the Starker's WP theme from starkers
My question is, as this is an updated theme based on new twentyten for WordPress 3.0, do I need all the code in the functions.php file as it all seems to make reference to default twentyten theme?
I'm am doing a CMS and was wondering if there is any important code I need in this functions.php file?
Thanks.

It depends on what stuff you are going to incorporate in your theme. You don't need that all unless you want.
The minimum you need is for sidebar integration, here is an example:
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div class="side">',
'after_widget' => '</div></div>',
'before_title' => '<div class="sidebar_title">',
'after_title' => '</div><div class="side_content">',
));
This is usually helpful when you want to assign what should come before or after the sidebar.
For example, I created a theme using Starker's theme and here is all what is present in my functions.php file:
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div class="side">',
'after_widget' => '</div></div>',
'before_title' => '<div class="sidebar_title">',
'after_title' => '</div><div class="side_content">',
));
// add thumbnail support to theme, options will be automatically visible in admin
if (function_exists('add_theme_support')) add_theme_support( 'post-thumbnails' );
?>

Related

How to create a widgetized sidebar for a theme with no sidebar?

Please could someone show me how to do this? My theme (Fable) does not have a built-in sidebar and I need one for my homepage.
Many thanks!
Create a child theme.
Create a file sidebar.php.
In your sidebar.php-file you have to use at least the following function: dynamic_sidebar()
Furthermore in your functions.php file of your child Theme you must use the following functions: register_sidebar()
Include the sidebar in your child theme (most probably in the overwritten index.php-file)
Style the sidebar to integrate it with your Theme properly.
For further documentation see the WordPress Codex:
https://codex.wordpress.org/Child_Themes
https://codex.wordpress.org/Function_Reference/dynamic_sidebar
https://codex.wordpress.org/Function_Reference/register_sidebar
Put this in your functions.php file:
<?php
// Declare sidebar widget zone
register_sidebars( 1,
array(
'name' => 'My Widget Area',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>'
)
);
?>
Then put this in the place in your theme where you want the widget area to appear:
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('My Widget Area')) : else : ?><?php endif; ?>

activate plugins on custom theme

I'm new to Wordpress and just created my first template.
In the functions.php I have put the following code, that function what I understand should call the plugins from the plugins directory:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Widgetized Area',
'id' => 'widgetized-area',
'description' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
}
I do see all the plugins, and in the widget screen I also see the 'widgets' screen and it allows me to drag widgets into the working area.
The website itself displays the plugin's html but neither js nor css is working.
What am I missing?
Above code that you have added in your functions.php is to register sidebar not to call any plugin. It do not have any connection to plugin.
You can call sidebar you added in template as follow:
if ( is_active_sidebar( 'widgetized-area' ) ) {
dynamic_sidebar( 'widgetized-area' );
}

wordpress plugin installation

I am learning wordpress. Now I want to install a simple photo gallery plugin. For that I have downloaded plugin from internet. Now how to integrate that so that I can find from the front-end in a particular position.
Thank you.
Your theme should have specific areas to put the plugins in.
If not You should open the php file of the template that you want to display the plugin in and add this code:
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Your plugin name') ) :
endif;
Now, open your functions.php and add this:
if ( function_exists('register_sidebar') ) {
register_sidebar( array(
'name' => 'Your plugin name',
'id' => 'login-widget',
'before_widget' => '<section class="login-widget">',
'after_widget' => '</section>',
'before_title' => '<span class="widget-title">',
'after_title' => '</span>')
);
}
after you are done with that, you can go to your administrator page, click on Appearance -> Widgets and then drag the plugin name from the list to the dock named "Your plugin name"

unregister_sidebar not working, what am I doing wrong?

I'm creating a child theme for twentyeleven. I want to remove all the sidebars specified by default, and add one of my own. In the twentyeleven themes functions.php is this:
<?php
// etc etc etc
function twentyeleven_widgets_init() {
register_widget( 'Twenty_Eleven_Ephemera_Widget' );
register_sidebar( array(
'name' => __( 'Main Sidebar', 'twentyeleven' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// etc. 4 others registered too...
}
add_action( 'widgets_init', 'twentyeleven_widgets_init' );
// etc etc etc
?>
Now I realise that if I just comment out the add action, this will remove them all. I dont want to do this thought because when the parent theme is updated they will re-appear.
I've attempted to do this in the child-theme's functions.php without success:
<?php
// etc etc etc
function unregister_old_sidebars() {
unregister_sidebar('sidebar-1');
//and i've tried unregister_sidebar('Main Sidebar');
}
add_action( 'widgets_init', 'unregister_old_sidebars' );
// etc etc etc
?>
Codex says to use unregister_sidebar($id) where $id is "The ID of the sidebar when it was added". So... I guess it's the 'widgets_init' action that's wrong? Do the child theme functions not run AFTER the parent functions?
Help! :D
Ben
Ok I'm an idiot. Answered my own question by actually READING the docs (http://codex.wordpress.org/Function_Reference/unregister_sidebar):
"In the example, note that we assign a priority of 11 when registering the widgets_init hook. This is because a child theme's functions.php file is called before the parent theme's, which means that our call to unregister_sidebar() would accomplish nothing since the sidebar has not yet been registered."

Adding widget area to functions.php causes blank screen after posting anything in admin

I'm following multiple tutorials that all tell me to put this into my functions.php to add a widget area:
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<div class="title">',
'after_title' => '</div>',
));
?>
Once I upload that file and try to change anything, like post or edit a post I get a white screen directly after hitting publish or any other action button.
Is there something wrong with that code? Or am I missing something when it comes to adding widget areas to my template?
Wordpress doesn't like blank lines on the functions.php page..

Resources