Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wordpress widgets

Featured Replies

Hi,

 

I am busy coding my first wordpress template and so far so good, go the header, footer and the content all in but I am stuck with the widgets.

 

How do I code the wordpress widgets into the sidebar.php?

its got my head spinning so if you have any advice or links to some good resources I would really appreciate the help.

 

Thanks,

You should find all you need in the wordpress codex :)

To be a bit more precise you can add in:

 

<?php
if ( function_exists('register_sidebar') )
   register_sidebar(array(
       'before_widget' => '',
       'after_widget' => '',
       'before_title' => '',
       'after_title' => '',
   ));
?>

into your functions.php file (if you don't have one just make it, put that in it and save it as functions.php)

 

And add in:

 

<?php if ( !function_exists('dynamic_sidebar')
       || !dynamic_sidebar() ) : ?>

into sidebar.php, but keep the sidebar widgets you'd like hardcoded into the theme. If no custom widgets are added, the hardcoded ones are displayed.

 

Make sure you keep ^ that php inside the div containing your sidebar so you can control it :)

 

Hope that helps. If you're still a bit confused just let me know and I'll go into more details :p

Edited by Malick

  • Author

You should find all you need in the wordpress codex :)

 

Ive been scouring in the wordpress codex all day an its become so confusing.

 

To be a bit more precise you can add in:

 

 

Thanks for the more detailed post, Ill defanitly give that a try ...

 

I know I had to do something in the functions.php file but its all so confusing when you are doing something new.

 

Ill keep at it and if I get stuck ill be sure to post an update , thanks for your help.

 

I was able to hard code some "widgets" into my sidebar but thought having it all done in widgets will give the user the option to change the order around of the widgets or to remove some unwanted ones if they decided to change.

 

or should I have both?

Ive been scouring in the wordpress codex all day an its become so confusing.

 

 

 

Thanks for the more detailed post, Ill defanitly give that a try ...

 

I know I had to do something in the functions.php file but its all so confusing when you are doing something new.

 

Ill keep at it and if I get stuck ill be sure to post an update , thanks for your help.

 

I was able to hard code some "widgets" into my sidebar but thought having it all done in widgets will give the user the option to change the order around of the widgets or to remove some unwanted ones if they decided to change.

 

or should I have both?

 

Yes you should have both. See put in the stuff you'd like in the sidebar as HTML in sidebar.php. But when you add the code i told you about and the user goes to "Appearance > Widgets" and adds a widget. It'll remove the hardcoded ones and replace them with the ones the user wants to have. If you want any HTML in particular before or after the widget or title just add it in between the apostrophes in the code i gave you to put into functions.php.

 

For example if you wanted to add a div class to every widget you'd change:

    'before_widget' => '',

 

into

 

   'before_widget' => '<div class="yourclass">',

 

Simple :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.