customize sidebar widget container items - wordpress

I developed a custom theme and register_sidebar in function.php to show menus on sidebar using Custom Menu (widget).
Then create a menu through Appearance-> Menu and set it in Widget's Sidebar area by using Custom Menu
Now I need to add an extra link for login page. This link should use extra class , which all other links/menu aren't using.
I added extra link through Appearance-> Menu but please help me to know how can I add a class for only that extra link (login)

$args = array(
'name' => __( 'Sidebar name', 'theme_text_domain' ),
'id' => 'unique-sidebar-id',
'description' => '',
'class' => 'PUT YOUR CLASS HERE', <=== here you can mention your class
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>' ); ?>
register_sidebar( $args );
Register sidebar Refer here

Related

Add image to sidebar module

I am trying to edit a website through Wordpress, but I'm not sure how to add an image to a sidebar.
In simple terms, what I want is for this page: https://www.kushnerhamed.com/attorneys/jeffrey-d-ubersax/
to have an image above the "Education" section like this page: https://www.kushnerhamed.com/attorneys/brandon-mordue/.
From what I could find, it involves using widgets, but they aren't in the Wordpress version I'm using (5.2.3). Any help would be appreciated.
Widgets have been around since version 2.8.
You could add this to your functions.php file. As stated in the Codex.
add_action( 'widgets_init', 'my_register_sidebars' );
function my_register_sidebars() {
/* Register the 'primary' sidebar. */
register_sidebar(
array(
'id' => 'primary',
'name' => __( 'Primary Sidebar' ),
'description' => __( 'A short description of the sidebar.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
/* Repeat register_sidebar() code for additional sidebars. */
}
The widget should now be available in the Widgets section of the Wordpress Admin.
Then you can add this to your theme template file to make the widget viewable in the front-end.
<div id="sidebar-primary" class="sidebar">
<?php dynamic_sidebar( 'primary' ); ?>
</div>

How to add additional css class to dynamic sidebar ( not widget ) in Wordpress?

What I'm trying is to add an additional class to my custom registered sidebar to frontend. From codex I can add a class when I'm registering a sidebar but it will show in admin area not on the frontend:
<?php register_sidebar( $args ); ?>
<?php $args = array(
'name' => __( 'Sidebar name', 'theme_text_domain' ),
'id' => 'unique-sidebar-id', // ID should be LOWERCASE ! ! !
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>' ); ?>
class - CSS class to assign to the Sidebar in the Appearance -> Widget admin page. This class will only appear in the source of the WordPress Widget admin page. It will not be included in the frontend of your website. Note: The value "sidebar" will be prepended to the class value. For example, a class of "tal" will result in a class value of "sidebar-tal". (default: empty).
Is it possible to add additional css class to dynamic sidebar without adding it through template?

Add a menu to a specific page?

I'm working on a WordPress website and I would like to add a menu that only shows up on a specific page. I have my main navigation set up as follows:
Home | Team | Leagues | Media | Links
And I would like it so that after you go to the media page, there is a sidebar menu that has links to pages like:
Media
-> Images
-> Videos
How can I go about doing this?
1) Create a new template for the page you need (in theme folder). Set the template as newly created under the Page attributes in your page area.
/*
Template Name: Dashboard
*/
2) Register new menu location in the functions.php.
register_sidebar( array(
'name' => __( 'new name', 'theme name' ),
'id' => 'new id',
'description' => __( 'description', 'theme name' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
3)Create new menu and assign pages into the new menu and assign the nav location as new menu location.
4)Go to the newly created page in theme folder and call the newly registered menu location where exactly you need.
The easy way would be to create a new file called page-media.php in
your theme directory. So when you click on media this file will be
executed. In this file paste all the code that you currently have in
page.php.
Then open functions.php and register a new side bar.
register_sidebar( array(
'name' => __( 'new name', 'theme name' ),
'id' => 'sidebar-1',
'description' => __( 'description', 'theme name' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
then show the sidebar in page-media.php with this code where ever you want.
dynamic_sidebar( 'sidebar-1' );

Wordpress variables

In my Wordpress page I have on many pages repeating info, Like: "this year we have sold 1000 cars" and I wanna update the number from one place for all pages.
How should I do it? Some plugin? Thanks
The circumstances thus need a custom widget area. In order to create a custom widget area do the following.
Add the following code to your functions.php
// Custom widget area.
register_sidebar( array(
'name' => __( 'Custom Widget Area'),
'id' => 'custom-widget-area',
'description' => __( 'An optional custom widget area for your site', 'twentyfourteen' ),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
Add the below code to where you want the widget get displayed.
dynamic_sidebar( 'Custom Widget Area' );
This will solve your problem.
Do not forget to add text widget to the Custom Widget Area in Menu > Appearance > Widgets.

How To Give Widgets Individual ID's or Classes?

On my wordpress installation, I created a new theme for a new page template I created. However, when I goto create new widgets, each widget automatically gets the class of "textwidget". I have two different styles I have for widgets that require different styles, so I'm not too sure how to give each indivudal widget a different class or to label them differently?
Anyone know how to do this?
Here's a page from my site with the 2 widgets: http://www.simonsayswebsites.com/how-we-get-you-more-customers/
You can see each one is within a widget that has the same class name.
This is what I added to my page functions.php to add the widget:
if ( function_exists('register_sidebar') ){
register_sidebar(array(
'name' => 'sidebarpage',
'before_widget' => '<div id="sidebarpage">',
'after_widget' => '</div>',
'before_title' => '',
'after_title' => '',
));
}
And here's the snippet from the page template itself for it to display:
<?php /* Widgetized sidebar */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebarpage') ) : ?><?php endif; ?>
I could make it using different widgetized areas, but want to learn about having individual widget styles.
You are mistaking name and id.
Also, in before_widget, you shouldn't declare a fixed ID, in your site both Widgets have the same ID and that's... no good.
If you follow the example in the Codex, your widget will receive an unique ID and a relevant class.
http://codex.wordpress.org/Function_Reference/register_sidebar
Default usage
<?php $args = array(
'name' => __( 'Sidebar name', 'theme_text_domain' ),
'id' => 'unique-sidebar-id',
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>' ); ?>

Resources