I'm creating my first wordpress template and I want to add custom widget areas to my footer or my home.php file(tried both without any effects). I've already registered widget area in functions.php file and the only thing I get when I go to Customize > Widgets is:
The code i have is copy pasted from a tutorial website
Could anyone tell me what am I doing wrong ? How can I add any widget area ? Thank you for any tips in advance.
I tried registering them by putting code into function and calling:
add_action('widgets_init','smth)
but by using that style my wordpress doesn't show any additional widget area in customize>widgets
FUNCTIONS.PHP CODE(widgets at the bottom):
<?php
add_theme_support('post-thumbnails');
add_theme_support('menus');
/**
* Enqueue scripts
*
* @param string $handle Script name
* @param string $src Script url
* @param array $deps (optional) Array of script names on which this script depends
* @param string|bool $ver (optional) Script version (used for cache busting), set to null to disable
* @param bool $in_footer (optional) Whether to enqueue the script before </head> or before </body>
*/
function theme_styles() {
wp_enqueue_style('bootstrap_css',get_template_directory_uri().'/css/bootstrap.min.css');
wp_enqueue_style( 'main_css', get_template_directory_uri().'/style.css');
wp_enqueue_style('owl_carousel_css',
get_template_directory_uri().'/owl_carousel/dist/assets/owl.carousel.min.css');
wp_enqueue_style('owl_carousel_theme_css',
get_template_directory_uri().'/owl_carousel/dist/assets/owl.theme.default.min.css');
wp_enqueue_style('font-awesome',
get_template_directory_uri().'/font-awesome47/css/font-awesome.min.css');
}
add_action( 'wp_enqueue_scripts', 'theme_styles' );
/**
* Enqueue scripts
*
* @param string $handle Script name
* @param string $src Script url
* @param array $deps (optional) Array of script names on which this script depends
* @param string|bool $ver (optional) Script version (used for cache busting), set to null to disable
* @param bool $in_footer (optional) Whether to enqueue the script before </head> or before </body>
*/
function theme_js() {
global $wp_scripts;
wp_enqueue_script('jquery','https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true);
wp_enqueue_script( 'bootstrap_js', get_template_directory_uri().'/js/bootstrap.min.js', array( 'jquery' ), false, false);
wp_enqueue_script('owl_carousel',
get_template_directory_uri().'/owl_carousel/dist/owl.carousel.min.js', array('jquery'),false,true);
}
add_action( 'wp_enqueue_scripts', 'theme_js' );
add_action( 'init', 'create_post_type' );
function create_post_type(){
register_post_type('slider',
array(
'labels'=>array(
'name'=>__('Slider'),
'signular_name'=>__('Slider')
),
'public'=>true,
'has_archive'=>false,
'supports'=> array(
'title',
'editor',
'excerpt',
'thumbnail',
'custom-fields',
'revisions'
)
)
);
}
function mytheme_customize_register( $wp_customize ) {
$wp_customize->add_section( 'themeslug_logo_section' , array(
'title' => __( 'Logo', 'themeslug' ),
'priority' => 30,
'description' => 'Upload a logo to replace the default site name and
description in the header',
) );
$wp_customize->add_setting( 'themeslug_logo' );
$wp_customize->add_control( new WP_Customize_Image_Control(
$wp_customize, 'themeslug_logo', array(
'label' => __( 'Logo', 'themeslug' ),
'section' => 'themeslug_logo_section',
'settings' => 'themeslug_logo',
) ) );
}
add_action( 'customize_register', 'mytheme_customize_register' );
add_action( 'customize_register', 'genesischild_register_theme_customizer' );
/*
* Register Our Customizer Stuff Here
*/
function genesischild_register_theme_customizer( $wp_customize ) {
// Create custom panel.
$wp_customize->add_panel( 'text_blocks', array(
'priority' => 500,
'theme_supports' => '',
'title' => __( 'Text Blocks', 'agrowinnica' ),
'description' => __( 'Set editable text for certain content.', 'agrowinnica' ),
) );
// Add Footer Text
// Add section.
$wp_customize->add_section( 'custom_footer_text' , array(
'title' => __('Change Footer Text','agrowinnica'),
'panel' => 'text_blocks',
'priority' => 10
) );
$wp_customize->add_section('big_text',array(
'title'=>__('Duży tekst','agrowinnica'),
));
// Add setting
$wp_customize->add_setting( 'footer_text_block', array(
'default' => __( 'default text', 'agrowinnica' ),
'sanitize_callback' => 'sanitize_text'
) );
$wp_customize->add_setting( 'big_text_block', array(
'default' => __( 'default text', 'agrowinnica' ),
'sanitize_callback' => 'sanitize_text'
) );
// Add control
$wp_customize->add_control( new WP_Customize_Control(
$wp_customize,
'custom_footer_text',
array(
'label' => __( 'Footer Text', 'agrowinnica' ),
'section' => 'custom_footer_text',
'settings' => 'footer_text_block',
'type' => 'text'
)
)
);
$wp_customize->add_control(new WP_Customize_Control(
$wp_customize,
'big_text',
array(
'label'=>__('Duży tekst','agrowinnica'),
'section'=>'big_text',
'settings'=>'big_text_block',
'type' =>'text'
)
)
);
register_sidebar( array(
'name' => 'Footer Sidebar 1',
'id' => 'footer-sidebar-1',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
// Sanitize text
function sanitize_text( $text ) {
return sanitize_text_field( $text );
}
register_sidebar(array(
'name' => 'O nas',
'id' => 'o-nas',
'description' => 'O nas',
'before_widget' => '<div id="one" class="two">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'O naso',
'id' => 'studio-text',
'description' => 'Studia',
'before_widget' => '<div id="one" class="two">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
function wpb_widgets_init() {
register_sidebar( array(
'name' => 'Custom Header Widget Area',
'id' => 'custom-header-widget',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="chw-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wpb_widgets_init',0 );
}
FOOTER.PHP
<?php wp_footer(); ?>
<footer>
<p class="footer-text">
<?php echo get_theme_mod( 'footer_text_block'); ?>
<?php
if(is_active_sidebar('footer-sidebar-1')){
dynamic_sidebar('footer-sidebar-1');
}
?>
</p>
</footer>
</body>
</html>
register_sidebar
in a function and did aadd_action('widgets_init', 'wrap_register_sidebar_func');
?doesn't seem to see the widget area
the widget are doesnt show in the backend?add_action
for a lot of reasons, if it's not working properly something it's happening with your theme