Developing Theme in Wordpress - Widgets do not appear

Asked

Viewed 1,052 times

0

I’m trying to develop a theme, from scratch, in Wordpress, accompanying video lessons. The problem didn’t just happen to me, there are people commenting on the same problem that is the fact that, after all the PHP, HTML and CSS coding aimed at creating widgets, they just don’t appear.

/*Na página index.php*/
<div class="right_sidebar"><?php get_sidebar(); ?></div>

/*Na página function.php*/
<?php
    if(function_exists('register_sidebar'))
        register_sidebar(array(
            'before_widget' => '<div class="widgets">',
            'after_widget' => '</div>',
            'before_title' => '<h2>',
            'after_title' => '</h2>',
        ));
?>

/*Na página style.css*/
.sidebar .widgets{
    width: 210px;
    background-color: #EEE;
    border: 1px solid #CCC;
    padding: 18px;
    font-size: 15px;
    color: #CCC;
    margin-top: 40px;
}

.sidebar .widgets h3{
    font-family: Helvetica;
    color: #333;
}

That code doesn’t seem to work at all.

Thank you from now on here.

  • I found the reason for the "error". In fact, the version used by the video lessons are outdated. To enable these options, the newest versions of Wordpress have their own activation features at the time of code development.

1 answer

2


The truth is that’s not even what’s missing.

What is missing is the "linked" sidebar.php file with the sidebar you want to display. I usually use it like this:

<ul id="sidebar">
  <?php dynamic_sidebar( 'right-sidebar' ); ?>
</ul>

Remembering that the right-sidebar is the id (or name) of your sidebar. If you want to generate your own sidebar, strongly recommend the site Generatewp.

Then just paste the code into your functions.php:

// Register Sidebar
function custom_sidebar() {

    $args = array(
        'id'            => 'right-sidebar',
        'name'          => __( 'Sidebar Direita', 'text_domain' ),
    );
    register_sidebar( $args );

}

// Hook into the 'widgets_init' action
add_action( 'widgets_init', 'custom_sidebar' );
  • 1

    Thank you for answering. Actually, I was talking about the file created inside the folder. It is that in the video class did not demonstrate, step by step to create this file and how to recover that file on my pages. And I’ll take a look at Generatewp. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.