• Resolved guennionline

    (@guennionline)


    I have the following Code in my functions.php:

    
    // Filter to use Shortcode in Text Widgets
    add_filter('widget_text', 'do_shortcode');
    
    // Filter to use Shortcode in Navigation Menus
    add_filter('wp_nav_menu', 'do_shortcode', 11);
    
    // [fa set="fas" icon="wordpress"]
    function faicon_shortcode( $atts ) {
    	$a = shortcode_atts( array(
    		'set' => 'fas',
    		'icon' => 'wordpress',
            'size' => '',
            'color' => '',
    	), $atts );
        
        // Check if Icon Size is Set
        if (isset($a['size']) && $a['size'] !== ''){
            $icon_size = ' fa-' . $a['size'];
        } else {
            $icon_size = '';
        }
    
        // Check if Icon Color is Set
        if (isset($a['color']) && $a['color'] !== ''){
            $icon_color = ' style="color: '.$a['color'].';"';
        } else {
            $icon_color = '';
        }
       
        // Generated Code to insert
    	return '<i class="'.$a['set'].' fa-'.$a['icon'].$icon_size.'"'.$icon_color.'></i>';
    }
    add_shortcode( 'fa', 'faicon_shortcode' );
    

    So far it has worked great. Recently, however, it hasn’t worked anymore. Does anybody have any idea what could be causing it In the widget the icon is displayed. In the navigation menu the i-tag is shown but the icon does not appear!

    Would be grateful for a tip!

    Greeting Sascha

Viewing 5 replies - 1 through 5 (of 5 total)
  • A URL would help.
    The most likely cause is your font-awesome library has been updated along with your theme.

    Try changing this :
    return '<i class="'.$a['set'].' fa-'.$a['icon'].$icon_size.'"'.$icon_color.'></i>';

    to this :
    return '<i class="'.$a['set'].' fab-'.$a['icon'].$icon_size.'"'.$icon_color.'></i>';
    or this :
    return '<i class="'.$a['set'].' fas-'.$a['icon'].$icon_size.'"'.$icon_color.'></i>';

    Thread Starter guennionline

    (@guennionline)

    Thanks for the quick answer.

    The icon is displayed correctly in the Footer Widget. Only in the wp_nav_menu it is not processed correctly. So it’s not the actual HTML code, but WordPress suddenly doesn’t process the shortcode correctly in the menu.

    Apparently, the following command is no longer processed correctly:

    // Filter to use Shortcode in Navigation Menus
    add_filter('wp_nav_menu', 'do_shortcode', 11);
    Thread Starter guennionline

    (@guennionline)

    I found the problem, these lines of code:

    // Generated Code to insert
    	return '<i class="'.$a['set'].' fa-'.$a['icon'].$icon_size.'"'.$icon_color.'></i>';

    generates the following in the Footer Widget (works fine):

    <i class="fas fa-home"></i>

    But in the navigation menu the following (not working):

    <i class="fas fa-“home”"></i>

    Obviously additional quotation marks are used here for whatever reason!

    That is curious!?

    • This reply was modified 4 years, 5 months ago by guennionline.
    • This reply was modified 4 years, 5 months ago by guennionline.

    Agree it’s curious.
    There is certainly nothing wrong with your syntax :
    https://phpcodechecker.com/
    return ‘<i class=”‘.$a[‘set’].’ fa-‘.$a[‘icon’].$icon_size.'”‘.$icon_color.’></i>’;

    As a work around, can you just replace your menu item using the FA directly ?
    <i class=”fab fa-facebook-f”></i>
    or
    <i class=”fa fa-facebook-f”></i>

    Thread Starter guennionline

    (@guennionline)

    The problem was another plugin that generated the extra quotes in the menu. Had to set it differently, now everything works again.

    90% of the errors sit in front of the monitor.

    Thanks for your help

    Regards Sascha

    • This reply was modified 4 years, 5 months ago by guennionline.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shortcode in Menu no longer works.’ is closed to new replies.