• Resolved igorsmrek

    (@igorsmrek)


    Hi.

    I am about to combine 2 codes and one is affecting the other. Both of them works nice if not combined, no issues. If phone number icon is active and I add Like button, phone icon is not visible.

    added to Functions.php

    Add a custom Phone Number Font Awesome icon to the Social Icons
    https://presscustomizr.com/snippet/add-custom-phone-number-font-awesome-icon-social-icons/
    Adding a Facebook like button in the header
    https://presscustomizr.com/snippet/adding-a-facebook-like-button-in-the-header/

    /** adds the script in the head of your theme */
    add_action (‘wp_head’ , ‘add_fb_button_script’);
    function add_fb_button_script() {
    ?>
    <div id=”fb-root”></div>
    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = “//connect.facebook.net/cs_CZ/sdk.js#xfbml=1&version=v2.7”;
    fjs.parentNode.insertBefore(js, fjs);
    }(document, ‘script’, ‘facebook-jssdk’));</script>
    <?php
    }

    /** adds the button on the right to the social icons in header */
    add_filter (‘tc_social_in_header’ , ‘add_fb_button’, 10, 2);
    function add_fb_button($html, $resp) {
    $class = (‘resp’ == $resp) ? ”:’span5′
    ?>
    <div class=”social-block <?php echo $class ?>”>
    <?php if ( 0 != tc__f( ‘__get_option’, ‘tc_social_in_header’) ) : ?>
    <?php echo tc__f( ‘__get_socials’ ) ?>
    <?php endif; ?>
    <div class=”fb-like” data-href=”https://www.facebook.com/dvereprovily/&#8221; data-width=”50″ data-layout=”button_count” data-action=”like” data-size=”large” data-show-faces=”true” data-share=”false”></div> <!–.social-block–>
    <?php
    }

    And position of menu and basket in a mobile view changes as well. Moves to the second line and is not on the right side as usually .

    Help how to combine both options would be very appreciated.
    Thank you.
    Igor
    https://www.dvereprovily.cz

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,
    Why don’t you try combining both together like below?

    /** adds the script in the head of your theme */
    add_action ('wp_head' , 'add_fb_button_script');
    function add_fb_button_script() {
    ?>
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/cs_CZ/sdk.js#xfbml=1&version=v2.7";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    <?php
    }
    
    /** adds the button on the right to the social icons in header */
    add_filter ('tc_social_in_header' , 'add_fb_button', 10, 2);
    function add_fb_button($html, $resp) {
    $class = ('resp' == $resp) ? '':'span5'
    ?>
    <div class="social-block <?php echo $class ?>">
    <?php if ( 0 != tc__f( '__get_option', 'tc_social_in_header') ) : ?>
    <?php echo tc__f( '__get_socials' ) ?>
    <a class="social-icon" href="tel:+1 123-456-7890" title="Call us" target="_self"><span class="fa fa-phone"></a>
    <?php endif; ?>
    <div class="fb-like" data-href="https://www.facebook.com/dvereprovily/" data-width="50" data-layout="button_count" data-action="like" data-size="large" data-show-faces="true" data-share="false"></div> <!--.social-block-->
    <?php
    }

    Just change the function name to something that indicates both, say add_fb_and_phone or something along those lines.

    Thread Starter igorsmrek

    (@igorsmrek)

    Hi Menaka,
    Appreciate your answer, but I have close to 0 coding skills and on top, I haven’t copied entire code. ?? If somebody on this forum can merge these codes bellow to make it copy/paste solution that would be nice.

    /********************************************************/
    /* Add a custom Phone Number icon to the Social Icons
    /********************************************************
    // Header section
    add_filter ( ‘tc_social_in_header’ , ‘custom_icon_phone_number’ );
    function custom_icon_phone_number() {
    //class
    $class = apply_filters( ‘tc_social_header_block_class’, ‘span5’ );
    ob_start();
    ?>
    <div class=”social-block <?php echo $class ?>”>
    <?php if ( 0 != tc__f( ‘__get_option’, ‘tc_social_in_header’) ) : ?>
    <?php echo tc__f( ‘__get_socials’ ) ?>
    <span class=”fa fa-phone”>
    <?php endif; ?>
    </div>
    <?php
    $html = ob_get_contents();
    ob_end_clean();
    return $html;
    }
    ********************************************************/
    /** adds the script in the head of your theme */
    add_action (‘wp_head’ , ‘add_fb_button_script’);
    function add_fb_button_script() {
    ?>
    <div id=”fb-root”></div>
    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = “//connect.facebook.net/cs_CZ/sdk.js#xfbml=1&version=v2.7”;
    fjs.parentNode.insertBefore(js, fjs);
    }(document, ‘script’, ‘facebook-jssdk’));</script>
    <?php
    }

    /** adds the button on the right to the social icons in header */
    add_filter (‘tc_social_in_header’ , ‘add_fb_button’, 10, 2);
    function add_fb_button($html, $resp) {
    $class = (‘resp’ == $resp) ? ”:’span5′
    ?>
    <div class=”social-block <?php echo $class ?>”>
    <?php if ( 0 != tc__f( ‘__get_option’, ‘tc_social_in_header’) ) : ?>
    <?php echo tc__f( ‘__get_socials’ ) ?>
    <?php endif; ?>
    <div class=”fb-like” data-href=”https://www.facebook.com/dvereprovily/&#8221; data-width=”50″ data-layout=”button_count” data-action=”like” data-size=”large” data-show-faces=”true” data-share=”false”></div> <!–.social-block–>
    <?php
    }

    Thank you
    Igor

    Hi,
    I have given the combined code. Use it as is if you are not comfortable changing function names. Just remove the earlier code that you had..

    Thread Starter igorsmrek

    (@igorsmrek)

    Hi Menaka,
    I am sorry but its confusing. Code I have uploaded is the same as you copied.

    My last post shows 3 different codes which I may need to combine.
    1. related to phone number icon add_filter ( ‘tc_social_in_header’ , ‘custom_icon_phone_number’ );
    2. Facebook like button – consists of 2 codes add_action (‘wp_head’ , ‘add_fb_button_script’);
    add_filter (‘tc_social_in_header’ , ‘add_fb_button’, 10, 2);

    Thank you
    Igor

    Hi,
    Remove all the code – both for fb button and phone number… and add the below code. It has both combined.

    
    /** adds the script in the head of your theme */
    add_action ('wp_head' , 'add_fb_button_script');
    function add_fb_button_script() {
    ?>
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/cs_CZ/sdk.js#xfbml=1&version=v2.7";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    <?php
    }
    
    /** adds the button on the right to the social icons in header */
    add_filter ('tc_social_in_header' , 'add_fb_button', 10, 2);
    function add_fb_button($html, $resp) {
    $class = ('resp' == $resp) ? '':'span5'
    ?>
    <div class="social-block <?php echo $class ?>">
    <?php if ( 0 != tc__f( '__get_option', 'tc_social_in_header') ) : ?>
    <?php echo tc__f( '__get_socials' ) ?>
    <a class="social-icon" href="tel:+1 123-456-7890" title="Call us" target="_self"><span class="fa fa-phone"></a>
    <?php endif; ?>
    <div class="fb-like" data-href="https://www.facebook.com/dvereprovily/" data-width="50" data-layout="button_count" data-action="like" data-size="large" data-show-faces="true" data-share="false"></div> <!--.social-block-->
    <?php
    }
    Thread Starter igorsmrek

    (@igorsmrek)

    Hi Menaka.
    Your help is greatly appreciated and the code work fine. Many thanks for help.
    Once again
    Thank you
    Igor

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add a custom Phone Number and facebook Like button – only one icon visible’ is closed to new replies.