icon-functions.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * SVG icons related functions
  4. *
  5. * @package Seedlet
  6. * @since 1.0.0
  7. */
  8. /**
  9. * Gets the SVG code for a given icon.
  10. */
  11. function seedlet_get_icon_svg( $icon, $size = 24 ) {
  12. return Seedlet_SVG_Icons::get_svg( 'ui', $icon, $size );
  13. }
  14. /**
  15. * Gets the SVG code for a given social icon.
  16. */
  17. function seedlet_get_social_icon_svg( $icon, $size = 24 ) {
  18. return Seedlet_SVG_Icons::get_svg( 'social', $icon, $size );
  19. }
  20. /**
  21. * Detects the social network from a URL and returns the SVG code for its icon.
  22. */
  23. function seedlet_get_social_link_svg( $uri, $size = 24 ) {
  24. return Seedlet_SVG_Icons::get_social_link_svg( $uri, $size );
  25. }
  26. /**
  27. * Display SVG icons in social links menu.
  28. *
  29. * @param string $item_output The menu item output.
  30. * @param WP_Post $item Menu item object.
  31. * @param int $depth Depth of the menu.
  32. * @param array $args wp_nav_menu() arguments.
  33. * @return string $item_output The menu item output with social icon.
  34. */
  35. function seedlet_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
  36. // Change SVG icon inside social links menu if there is supported URL.
  37. if ( 'social' === $args->theme_location ) {
  38. $svg = seedlet_get_social_link_svg( $item->url, 26 );
  39. if ( empty( $svg ) ) {
  40. $svg = seedlet_get_icon_svg( 'link' );
  41. }
  42. $item_output = str_replace( $args->link_after, '</span>' . $svg, $item_output );
  43. }
  44. return $item_output;
  45. }
  46. add_filter( 'walker_nav_menu_start_el', 'seedlet_nav_menu_social_icons', 10, 4 );