[Resolved] Strange issue with dashicons

Home Forums Support Strange issue with dashicons

This topic contains 6 replies, has 2 voices, and was last updated by  Leo 2 months, 2 weeks ago.

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

    George

    I have a strange issue. I am including dashicons on the front-end through

    add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
    function load_dashicons_front_end() {
    	wp_enqueue_style( 'dashicons' );
    }

    Then I enter dashicon HTML in the Navigation Label of my menu items, for example:
    <span class="dashicons dashicons-admin-home"></span> Home

    I also have a wp-head hook only on the blog archive that truncates the post titles to the first 7 words:

    <?php
    
    add_filter( 'the_title', 'wpse_75691_trim_words' );
    
    function wpse_75691_trim_words( $title )
    {
    	// limit to 7 words
    	return wp_trim_words( $title, 7, '...' );
    }
    
    ?>

    It works for the whole site except the blog archive where the dashicons disappear from the menu items. Removing the truncate script gets the icons back again on the blog archive. Settings the hook to wp_footer is a no-go since it doesn’t work.

    I have tried different priorities for both scripts but nothing. Also nothing in the logs. I have also tried putting the truncate script in functions.php instead of a hook, same problem.

    #1194979

    Leo Customer Support

    Hi there,

    That’s strange.

    Does the problem only occur on the main posts page? What about archives etc?

    Any chance you can try a twenty series default theme and see if the same issue occurs?

    Let me know 🙂

    #1194990

    George

    Hi Leo.

    Yeah, it happens with a twenty them as well. It occurs wherever that truncate code exists. If I activate it for the entire site, it will strip icons from the entire site. It seems it’s not theme-specific. I believe, I have this problem here:

    https://wordpress.org/support/topic/problem-displaying-font-awesome-after-wp_trim_words/

    but for dashicons.

    Still, no idea how it can be solved, though…If you can suggest something, I will take it!

    #1195126

    Leo Customer Support

    Sorry I don’t have a suggestion for this.

    Maybe ask on a forum like this?
    https://wordpress.stackexchange.com/

    #1195560

    George

    I will, thanks Leo.

    #1195579

    George

    I received the solution on this thread.

    <?php
    
    function wpse_360758_trim_words( $title, $post_id ) {
        if ( is_admin() ) {
            return $title;
        }
    
        if ( in_the_loop() && 'post' === get_post_type( $post_id ) ) {
            $title = wp_trim_words( $title, 7, '...' );
        }
    
        return $title;
    }
    add_filter( 'the_title', 'wpse_360758_trim_words', 10, 2 );
    
    ?>

    Thanks again!

    #1195627

    Leo Customer Support

    Glad you found a solution!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.