- This topic has 6 replies, 2 voices, and was last updated 4 years ago by Leo.
-
AuthorPosts
-
March 14, 2020 at 12:24 pm #1194967George
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.
March 14, 2020 at 1:54 pm #1194979LeoStaffCustomer SupportHi 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 🙂
March 14, 2020 at 2:25 pm #1194990GeorgeHi 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!
March 14, 2020 at 7:40 pm #1195126LeoStaffCustomer SupportSorry I don’t have a suggestion for this.
Maybe ask on a forum like this?
https://wordpress.stackexchange.com/March 15, 2020 at 7:16 am #1195560GeorgeI will, thanks Leo.
March 15, 2020 at 7:54 am #1195579GeorgeI 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!
March 15, 2020 at 9:20 am #1195627LeoStaffCustomer SupportGlad you found a solution!
-
AuthorPosts
- You must be logged in to reply to this topic.