Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #1277647

    Hi,

    I want to add a widget on every blog-post site after the main content, but before the sidebar.
    When I add a widget to “display everywhere” it is added after the sidebar, so this does not help.
    I could also add a custom widget area to each page, but I would prefer a “global” solution for all posts.

    I already found this:

    add_action( 'ava_after_content', 'enfold_customization_category_widget_area' );
    	function enfold_customization_category_widget_area() {
    	if (is_singular(post)) {
    	  dynamic_sidebar( 'my-sidebar-name' );
    	}
    }

    … but the hook “ava_after_content” does not seem to work.
    Other hooks like ava_after_main_container or ava_before_footer work fine, but that’s not the position I need.

    Any suggestions?

    #1277667

    try a different if-clause !

    add_action( 'ava_after_content', 'enfold_customization_category_widget_area' );
    function enfold_customization_category_widget_area() {
    	if (is_singular('post')) {
    	  dynamic_sidebar( 'my-sidebar-name' );
    	}
    }

    or use: if(is_single()){

    if you like to have that on portfolio too use:
    if(is_singular('post') || is_singular('portfolio')){

    #1277669

    Hi.
    it’s not really a matter of the if-clause. It’s obviously a matter of “ava_after_content”.
    As I said, it works with different hooks like ava_after_main_container or ava_before_footer, but ava_after_content has no effect at all…

    Or maybe I misunderstand the name of this hook…
    I just realized, my widget is added at blog archive pages to ALL posts…
    That’s also not what I need…

    So the basic question is: How can I add a widget after my blog content, before the sidebar.

    PS: Unfortunately our code has no effect at all…

    #1277670

    The hook determines only the place where it is inserted.
    Did you create that widget-area at Widgets : “my-sidebar-name” ?

    Are these single posts created with classic editor or with advanced Layout Builder ?

    Try one post with classic editor!

    #1277676

    Yes, I know.
    I need a hook for the position after the content, before the sidebar.
    As I said, it already works with other hooks like ava_after_main_container or ava_before_footer, so yes, my widget “my-sidebar-name” exists.

    For me, the hook ava_after_content sounded like what I was looking for, but maybe I was wrong.

    I’m posting with the ALB, which is preferred (we even lost the share-box and the comments because of that, but the ALB is still preferred).
    The ava_after_content indeed works with the classic editor, but since the content is also inserted after every single post on archive pages, I assume it’s not the correct hook anyway…

    Maybe I have no other choice than using the insert-widget on every single post page.
    But maybe someone from kriesi has a better solution…?

    But thank you for your input, Günni :)

    #1277691

    maybe a mod knows a better way – you can do it with wordpress standard functions this way:
    ( you don’t need to insert that dynamic side bar manually – it is done by that code allready)

    just a moment – the given code is not totaly correct – it works but it is not at the end of content in all cases – sorry

    • This reply was modified 3 years, 9 months ago by Guenni007.
    #1277701

    Hi,

    thanks a lot.
    Where do I have to enter this code?

    When I enter it at the /themes/enfold/functions.php it has no effect…

    When I enter it at wp-includes/widgets.php, my widget appears in the middle of my content -between an image and some text of the same textarea, which is kinda strange… it’s also added to my source code at this strange position…

    #1277707

    thats the reason why i erased it. ( All code goes to child-theme functions.php )

    i thought that we can use another filter of enfold:
    but this

    add_filter('avf_template_builder_content', 'avf_template_builder_content_comment_mod' , 10 , 1);
    function avf_template_builder_content_comment_mod($content = "")
    {
      if(is_singular('post') || is_singular('portfolio')){
        $sidebar_content = dynamic_sidebar( 'my-sidebar-name' );
        $content = $content . $sidebar_content ;
      }
      return $content;
    }

    inserts the widget area before ( allthough it is $content = $content . $sidebar_content ) content. ?
    Sorry – you had to wait for a mod

    #1277710

    OK here is a code that should work:

    add_filter('avf_template_builder_content', 'avf_template_builder_content_comment_mod' , 10 , 1);
    function avf_template_builder_content_comment_mod($content = "")
    {
      if(is_singular('post') || is_singular('portfolio')){
        $sidebar_content = do_shortcode("[av_sidebar widget_area='my-sidebar-name']");
        $content = $content . $sidebar_content ;
      }
      return $content;
    }

    remove the or portfolio clause if you do not want to include them!
    But the existing shortcode is only for those post/portfolios when they are made by Advanced Layout Builder

    #1277711

    YES! Thanks a lot!
    This indeed works great! :)

    Thank you VERY much :)

    #1277723

    This should work on both post with classic editor and posts with alb editor ( don’t know if it will work for Gutenberg):

    add_filter('the_content', function($content) {
         if (is_singular('post')) {
          $content .= '[av_sidebar widget_area="my-sidebar-name"]';
         }
         return $content;
       }
    );

    And if you got more than one widget in that widget area – you can play with flex layout to have those widgets besides each other :

    #main .avia-builder-widget-area {
      display: flex;
      flex-flow: row wrap;
      justify-content: space-between;
    }
    
    #main .avia-builder-widget-area::before, 
    #main .avia-builder-widget-area::after {
      display: none;
    }
    
    #main .avia-builder-widget-area .widget {
        padding: 0;
        margin-bottom: 30px;
    }
    #1277730

    That’s really great, thanks a lot for your help!

    BONUS-QUESTION:

    I’m using a page as footer. As this page also contains a content area… is there any way to hide my widget from the footer page?
    At the moment it is added after the content -.as I wanted…
    … but also after the content of the footer page…

    #1277740

    hm – that is strange because if the footer-page is a page – then this content shouldn’t be affected.

    you can do this to child-theme functions.php below the above code :

    function remove_widget_area_from_footer_page(){
    if (is_singular('post')) {
    ?>
    <script>
    (function($){
    $(window).on('load', function () {
    	$('#footer-page .avia-builder-widget-area').remove();
    });
    })(jQuery);
    </script>
    <?php
    }}
    add_action('wp_footer', 'remove_widget_area_from_footer_page');
    #1277754

    I’m already at home, so I’ll try it tomorrow.
    I also have another idea using the page_id to exclude the footer page, which also should work.
    I’ll post about it tomorrow.
    Again, thank you very much for now :)

    #1277884

    So, back at work…
    I added the page_id of the footer-page to the if-clause, so it does not appear in the footer anymore.
    This works fine for me.

    if((is_singular('post') || is_singular('portfolio')) && get_the_ID() != '106' && get_the_ID() != '107')

    106 = page_id of German footer, 107 = page_id of English footer
    yes, it’s very static, but the widget-name is also static, so it doesn’t really matter.

    PS: Ja, wir hätten wohl die ganze Zeit Deutsch schreiben können, aber ich hatte auf Englisch geschrieben, weil viele Mods hier Englisch sprechen. Aber nochmal vielen lieben Dank an Günni, Du hast mir mit Deinen Antworten wirklich SEHR geholfen :)

    #1277905

    Hi GrandmasterA,

    Thanks for the update. So everything is working as it should now then? Thanks @guenni007 for helping out :-)

    Best regards,
    Rikard

    #1277943

    maybe Günter could insert an extra class to that page ( similar to privacy-policy page ) which is set to be the footer-page

    where then in fact the question would be how to rewrite the code so that it works with a class to body.
    i tested of course !is_page(106) but even with the ID it does not work. so !is_page(‘kontact-section’) won’t work too.

    Thank you GrandmasterA for your addition to the if-clause.
    Preventing something from emerging is definitely better here than just hiding it later.

    #1277944

    Hi Rikard, yes, everything works as it should now.
    Thanks again, Günter :)

    #1278129

    Hi GrandmasterA,

    Great :)

    We are closing the thread.

    If you need further assistance please let us know in a new one.

    Best regards,
    Victoria

Viewing 19 posts - 1 through 19 (of 19 total)
  • The topic ‘Add custom widget after main content, but before sidebar’ is closed to new replies.