- This topic has 8 replies, 3 voices, and was last updated 10 months, 1 week ago by
Elvis.
-
AuthorPosts
-
April 7, 2019 at 3:22 pm #862316
Alex
I have enabled SVG uploads, now I’m wondering how I could use SVG code instead of an img?
GP Premium 1.7.8April 7, 2019 at 4:42 pm #862364Tom
Lead DeveloperLead DeveloperHi there,
If you’re wanting to use SVG code instead of an SVG as an image, you can use this filter:
add_filter( 'generate_logo_output', function() { return sprintf( // WPCS: XSS ok, sanitization ok. '<div class="site-logo"> <a href="%1$s" title="%2$s" rel="home"> YOUR SVG CODE HERE </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ) ); } );
Adding PHP: https://docs.generatepress.com/article/adding-php/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 26, 2022 at 3:15 am #2233166Elvis
Hello,
I would like to include svg as code so that I have more control over changes in its apparance over different pages/contexts.
I have tried using this function and it does not work for me. I tried with mobile header turned off and on, with use navigation as header on and off. None works?!
My site uses “use navigation as header” option, but I tried all the options trying to find out how to do it on another test site.
No html is generated.
I added snippet to functions.php and snippets plugin. Doesnt work either way.
Thanks
To understand recursion, you first have to understand recursion.
May 26, 2022 at 4:23 am #2233233David
StaffCustomer SupportHi there,
can we see site with the code added ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 26, 2022 at 6:55 am #2233391Elvis
Hi David,
this is my snippet:
add_filter( 'generate_logo_output', function() { return sprintf( // WPCS: XSS ok, sanitization ok. '<div class="site-logo"> <a href="%1$s" title="%2$s" rel="home"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 64 30" class="apuri-svg-logo" style="height:30px;width:64px"> <path fill="#000" fill-rule="evenodd" clip-rule="evenodd" d="M11 14 6 0 0 14h11Z"/> <path fill="#000" d="M26 26h-4v4h4v-4Z"/> <path fill="#000" fill-rule="evenodd" clip-rule="evenodd" d="M64 21a9 9 0 0 1-19 0V0h19v21ZM30 0a7 7 0 0 1 6 7 7 7 0 0 1-6 7h-4V0h4Z"/> </svg> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ) ); } );
The site is on the local dev server, but here I have one left over from before: https://aljosab10.sg-host.com
Not much to see like this, so tell me if you need a login?To understand recursion, you first have to understand recursion.
May 26, 2022 at 10:03 am #2233803Ying
StaffCustomer SupportHi there,
In order to make the code work, you’ll need to upload an image first at customizer > site identity.
May 26, 2022 at 11:54 am #2234014Elvis
Hi Ying,
thanks. I hadn-t expected to have to upload to be able to do it ๐ But I understand now, markup needs to be there to replace it with new one.
I tried now and it works.
https://aljosab10.sg-host.com/
Thanks
To understand recursion, you first have to understand recursion.
May 26, 2022 at 12:01 pm #2234028Ying
StaffCustomer SupportGreat! Glad it works ๐
May 27, 2022 at 2:58 am #2234935Elvis
Hello just adding here for others to have. This is how to implements embeded svg logo both in mobile and desktop menus.
function prefix_svg_logo() { return sprintf( // WPCS: XSS ok, sanitization ok. '<div class="site-logo"> <a href="%1$s" title="%2$s" rel="home"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 64 30" class="apuri-svg-logo" style="height:30px;width:64px"><path fill-rule="evenodd" clip-rule="evenodd" d="M11 14 6 0 0 14h11Z"/><path d="M26 26h-4v4h4v-4Z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M64 21a9 9 0 0 1-19 0V0h19v21ZM30 0a7 7 0 0 1 6 7 7 7 0 0 1-6 7h-4V0h4Z"/></svg> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ) ); } add_filter( 'generate_logo_output', 'prefix_svg_logo'); add_filter( 'generate_mobile_header_logo_output', 'prefix_svg_logo');
To understand recursion, you first have to understand recursion.
-
AuthorPosts
- You must be logged in to reply to this topic.