0

I want to add a widget below page content in my child theme. I used a function from here: https://codex.wordpress.org/Widgetizing_Themes and the widget is displayed where I want: enter image description here

but it is also displayed below page title (in div.entry-content). enter image description here

In functions.php I have:

function twentytwentychild_after_post_widget( $content ) {
    if ( is_singular( array( 'page' ) ) && is_active_sidebar( 'after-post' ) && is_main_query() ) {
        dynamic_sidebar('after-post');
    }
    return $content;
}
add_filter( 'the_content', 'twentytwentychild_after_post_widget' );

register_sidebar( array(
    'id'          => 'after-post',
    'name'        => 'After Page Content Widget',
    'description' => __( 'description.', 'twentytwentychild' ),
) );

and in page-gallery.php before ending </main> I have:

<?php if ( is_active_sidebar( 'after-post' ) ) : ?>
    <div class="footer-logo">
        <?php dynamic_sidebar( 'after-post' ); ?>
    </div>
<?php endif; ?>

Why it is displayed on the top and how can I fix it?

Any help would be appreciated.

1 Answer 1

0

OK, I used just normal function and it's ok.

function twentytwentychild_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Widget name', 'twentytwentychild' ),
        'id'            => 'after-post',
        'description'   => __( 'Widget desc.', 'twentytwentychild' ),
        'before_widget' => '',
        'after_widget'  => '',
        'before_title'  => '',
        'after_title'   => '',
    ) );
}
add_action( 'widgets_init', 'twentytwentychild_widgets_init' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.