I am using widgets in my wordpress theme and I need to remove the:
<div class="textwidget"></div>
that appears around the widget's content. I am using this in my function.php file:
if (function_exists('register_sidebar'))
register_sidebar(array('name'=>'Church Address',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<p class="bold">',
'after_title' => '</p>',
));
but I need to remove the div from around the text widget's body. Is there some way to do this?
I also have another question. When I put let's say, a tag in the before_widget and a in the after_widget shouldn't it put a paragraph tag around the entire widget? Instead, it put them both before the entire widget.
On your page.php the code should be something like:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Church Address') ) : ?>
<address>
<p class="bold">
The Church Address goes here if the sidebar isn't working or not loading
</p>
</address>
<?php endif; ?>
then enable your sidebar widget: admin->appearance->widgets
the code which is inside your functions.php file should be fine. although if using the p tag, I would encompass this in an address tag for better read ability, also its supported by all the major browsers..
if (function_exists('register_sidebar'))
register_sidebar(array('name'=>'Church Address',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<address class="bold">',
'after_title' => '</address>',
));
Related
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; ?>
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..
How can i add a custom widget to wp-admin/post-new.php?
Some themes use it, and i wan't to be able to do the same thing in my theme :)
Thanks
/Richard
You can create yourself a new side bar in functions.php, copy and paste one of the current ones, eg:
register_sidebar( array (
'name' => 'Primary Widget Area',
'id' => 'primary_widget_area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
Change any references to primary to a name of your choice maybe post-new
Then add this side bar to wp-admin/edit-form-advanced.php. Search for 'side-info-column'. Just before that div closes ad in the call to the new side bar:
<?php if ( is_sidebar_active('secondary_widget_area') ) : ?>
<div id="secondary" class="widget-area">
<ul class="xoxo">
<?php dynamic_sidebar('secondary_widget_area'); ?>
</ul>
</div><!-- #secondary .widget-area -->
<?php endif; ?>
Again, you can copy one of the current ones found in sidebar.php.
You can then go to dashboard > Appearance > Widgets and you should see your new sidebar there.
Hope that helps. I'll be happy to help more if needs be.
Found what I was looking for. Its called meta boxes and there are lots of tutorials how to implement them. Just Google it ;)
I need to display my custom made widget in WP page based custom page template programmatically.
This is the scenario:
I created page based on custom page template called "product" now I need in its sidebar display my custom made widget. I need this side bar to be totally different from other pages this is why I want to display it programmatically.
I tried to use the_widget() function but I think it works only with built in widgets and also I don't know how to pass parameters registered with register_sidebar function to it, because it seems it doesn't use them by default.
Actually I used this : the_widget('WP_Widget_Search') to test it and widget was there but it ignored theme settings, I mean settings in function.php :
register_sidebar( array(
'name' => 'Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<h3>',
'after_title' => '</h3><div class="padder">'
) );
So as I said I don't know if it works with custom made widgets (created in plugins) because I don't know how to pass widget name there and params. How to do that?
Dynamically create a dynamic instance of the widget using the_widget(), eg:
<div id="xxx" class="widget-area" role="complementary">
<div id="sidebar-dyn">
<?php the_widget( 'WP_Widget_Recent_Posts' ); ?>
</div>
</div>
Why the need to include custom widget programatically. I mean you can simply create another sidebar that is shown only on your custom page template "product"
Further as you need to do it for your custom page, you don't even need to check for any condition. Simply put this code in your "prdouct" page template file anywhere ( where you would like to display your sidebar".
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Product Sidebar')) ;?>
And simply drag your widget to this sidebar from admin panel.
If the widget has a shortcode, call it using this:
<?php echo do_shortcode( $content ) ?>
you're question isn't exactly clear to me, but what i am gathering is that
1. you need to register your widget and
2. you need for it to ONLY show on the product page.
to register, place this in functions.php (you may already have the first line in your functions file):
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name'=> 'Product Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<h3>',
'after_title' => '</h3><div class="padder">'
));
?>
this would be the code to include in sidebar.php to display the above only on the page called "Product".
<?php if (is_page('Product')) ;?>
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Product Sidebar')) ;?>
<?php endif; ?>
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' );
?>