• Resolved giorjoe

    (@giorjoe)


    Hi all,
    I add new widget area after header with this code (functions.php)
    // Adds a widget area.
    if (function_exists(‘register_sidebar’)) {
    register_sidebar(array(
    ‘name’ => ‘Extra Header Widget Area’,
    ‘id’ => ‘extra-widget-area’,
    ‘description’ => ‘Extra widget area after the header’,
    ‘before_widget’ => ‘<div class=”widget my-extra-widget”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h2>’,
    ‘after_title’ => ‘</h2>’
    ));
    }

    // Place the widget area after the header
    add_action (‘__after_header’, ‘add_my_widget_area’, 0);
    function add_my_widget_area() {
    if (function_exists(‘dynamic_sidebar’)) {
    dynamic_sidebar(‘Extra Header Widget Area’);
    }
    }

    But how can put this widget in page post or category after title? Thanks Joe

Viewing 14 replies - 1 through 14 (of 14 total)
  • What do you mean exactly with “page post or category”? You mean everywhere except home and after the, say the title of the post/archive/page ?

    Thread Starter giorjoe

    (@giorjoe)

    I would like to insert the widget after the all title (page, post, category), to be able to insert additional menus (with plugin jquery mega menu)

    Change hook.
    You can use:
    add_action ('__before_loop', 'add_my_widget_area', 20);
    instead of
    add_action ('__after_header', 'add_my_widget_area', 0);

    Is that what you wanted?

    Thread Starter giorjoe

    (@giorjoe)

    I would like to insert the widget under the title h2

    Since pages and posts pages don’t have an h2 (if you didn’t change it in customizr code or using a filter), I suppose you want to have a menu under each post title in lists of posts. Or you’re talking about the tagline in the header?
    Hey give me a picture ’cause clearly there’s something confusing here.

    Thread Starter giorjoe

    (@giorjoe)

    this is example:
    https://provaleague.altervista.org/wp-content/uploads/2014/03/Immagine1.jpg
    I want put this menu after title

    After “regolamento”?
    Why do you say it’s h2 ?
    Anyway, the first suggestion I gave you should do that, doesn’t it?

    That will work good just in singles (page or posts). Always assuming that was what you wanted to achieve, that’s the complete snippet:

    // Place the widget area after the header
    add_action ('wp_head', 'add_my_widget_area');
    function add_my_widget_area() {
        if (! function_exists('dynamic_sidebar'))
            return;
        $hook = null;
    
        if ( is_singular() && ! tc__f('__is_home'))
            $hook = '__before_content';
        elseif ( is_archive() )
            $hook = '__before_loop';
    
        if ( $hook )
            add_action ($hook,
                function(){
                    dynamic_sidebar('Extra Header Widget Area');
                },
                20
            );
        return;
    }
    Thread Starter giorjoe

    (@giorjoe)

    Perfect, work, thanks a lot D4, really thanks

    Really? Ahaha, I was starting to think I didn’t get anything of your real issue, what a relief.
    Glad you solved.
    Would you mind marking this topic as resolved?
    thank you

    Thread Starter giorjoe

    (@giorjoe)

    sorry ??

    Oh no don’t be sorry, I know it’s something “hidden”. ??

    Thread Starter giorjoe

    (@giorjoe)

    Sorry d4, and for put header widget after slider?

    Hey ??
    Open a new topic please, also be more specific, e.g. I don’t get, you want another widget area after the slider?

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘adding widget area’ is closed to new replies.