Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1473372

    Hi,
    have added a new widget with functions.php to make it 100% width bcs the page width is fixed.
    Now, i need to place a google map iframe same way as widget BUT this map widget should by only added to the contact page .. hwo do i need to create the function?

    This is what i used for the prevoious one:

    add_action('ava_before_footer','avia_above_footer');
        function avia_above_footer(){
        dynamic_sidebar( 'CTA-Footer' );
    }

    What should i replace to generate another 100% widget block above this one but only in the contact page?
    (When i use this code, the page breaks.)

    add_action('ava_before_footer','avia_above_footer');
        function avia_above_footer(){
        dynamic_sidebar( 'Maps' );
    }
    • This topic was modified 1 month, 1 week ago by xeovision.
    #1473379

    Hey Sebastian,

    You could try using the is_page conditional: https://developer.wordpress.org/reference/functions/is_page/

    Best regards,
    Rikard

    #1473381

    hmm .. i am looking for a add_action snippet like this one:

    add_action( 'ava_after_content', 'enfold_customization_category_widget_area' );
    function enfold_customization_category_widget_area() {
    	if (is_page(3416)) {
    	  dynamic_sidebar( 'Maps' );
    	}
    }
    #1473386

    the code breaks because function names should be unique! if you got “avia_above_footer” twice in your child-theme functions.php it will come to conflict.

    If you rearange your codesnippet above you see the similarity of your codes:

    function avia_above_footer(){
        dynamic_sidebar( 'Maps' );
    }
    add_action('ava_before_footer','avia_above_footer');

    now you see that you can use the same conditional usage of your “ava_after_content”
    to avoid having a similar function name you can rename the one function – or simply combine both rules in one function.

    function avia_above_footer(){
        dynamic_sidebar( 'CTA-Footer' );
        dynamic_sidebar( 'Maps' );
    }
    add_action('ava_before_footer','avia_above_footer');

    you can now wrap the one of those lines inside a conditional setting:

    function avia_above_footer(){
    	dynamic_sidebar( 'CTA-Footer' );
    	if (is_page(3416)) {
    		dynamic_sidebar( 'maps' );
    	}
    }
    add_action('ava_before_footer','avia_above_footer');
    #1473388

    I usually use this type of notation using a function name to help me remember what the function is supposed to do. However, this also requires a meaningful function name. Something like : insert_widget_before_footer
    Note that the function names are separated by an underscore.

    You can also use a notation that makes a function name superfluous:

    add_action('ava_before_footer', function() {
    	if (is_page(3416)) {
    		dynamic_sidebar( 'maps' );
    	}
    	dynamic_sidebar( 'CTA-Footer' );
    });

    Incidentally, there are plugins that build conditional logic into widgets. The standard plugin is complex but powerful; another small plugin is more intuitive to use: https://wordpress.org/plugins/widget-options/
    but all these rules the widgets itself and not the widget areas. But f.e. if you have one widget area – you can put in the cta-button and maps widget and determine that the maps widget only is shown on contact page.

    #1473414

    That works perfect.
    Thank you very much for the support and for the explanation.

    #1473423

    Hi,

    Thanks for the update, we’ll close this thread for now then. Please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Customized widget above another widget but only on one page’ is closed to new replies.