Support » Plugin: Leira Letter Avatar » Possible to change font?

  • Hi there

    Firstly, thanks for creating such a well-made plugin – exactly what I need!

    I was wondering what’s the best way to go about changing the font of the generated avatars? Looking at the plugin the font seems to be NotoSans – how can I change this to, say, Barlow?

    Thanks in advance!

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ariel

    (@arielhr1987)

    Hi @zee300

    Thanks for the kudos

    You could use something like this to use you own font.
    Just set the path the correct path to your font and delete your current “letter-avatar” folder in uploads dir (the plugin will generate it for you).
    Let me know if it works for you.

    function my_image_font( $font, $data ) {
    	$font = __DIR__ .'/Barlow-Regular.ttf';
    
    	return $font;
    }
    add_filter( 'leira_letter_avatar_image_font', 'my_image_font', 10, 2 );

    Kind regards

    Thread Starter elliesatt

    (@zee300)

    Awesome, thanks so much!

    So if I wanted to point to a font folder in my child theme, it should be something like this? I’m not sure if the path directory is correctly defined in my code below:

    function my_image_font( $font, $data ) {
    	$font = __DIR__ .'html/wp-content/themes/child_theme/fonts/Barlow-SemiBold.ttf';
    
    	return $font;
    }
    add_filter( 'leira_letter_avatar_image_font', 'my_image_font', 10, 2 );
    Plugin Author Ariel

    (@arielhr1987)

    avoid pointing to theme as you might want to delete the theme at some point and you will gonna break letter avatar.
    Put the ttf file in wp-content/uploads/ directory and use this code.

    function my_image_font( $font, $data ) {
    	$uploads = wp_get_upload_dir();
    	$uploads = $uploads['basedir'];
    
    	$font = $uploads . '/Barlow-SemiBold.ttf';
    
    	return $font;
    }
    add_filter( 'leira_letter_avatar_image_font', 'my_image_font', 10, 2 );
    Thread Starter elliesatt

    (@zee300)

    It doesn’t seem to work for me – I’ve put the font file in html/wp-content/uploads/Barlow-SemiBold.ttf and pasted your exact code in Code Snippets.

    I then deleted the Letter Avatar folder in /uploads – it’s regenerating, but still regenerating in the Noto font.

    Am I doing something wrong somewhere?

    Thanks for your help on this by the way!

    • This reply was modified 1 month, 1 week ago by elliesatt.
    Thread Starter elliesatt

    (@zee300)

    Thoughts? I’m a little bit at a loss here – apart from renaming my font file to replace the original, but I don’t think that’ll survive a plugin update… Thanks!

    Plugin Author Ariel

    (@arielhr1987)

    Did you remove the avatar folder in uploads directory? Otherwise image wont be regenerated

    Thread Starter elliesatt

    (@zee300)

    Yes I did – it just regenerates in Noto again.

    Am I executing the code right? I’m using Code Snippets (https://wordpress.org/plugins/code-snippets/) to insert the code you gave me.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.