Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter wearevilla

    (@wearevilla)

    a little more about this… i am using it in an options page to allow the user to change the fonts of the theme. i have extracted selected font name with the following:

    <?php
    $pFontField = get_field('p_font', 'option');
    	$pFont = array_values($pFontField)[0];
    	$addTitleFont = get_field('add_title_font', 'option');
    	if( $addTitleFont == true ) {
    		$titleFontField = get_field('title_font', 'option');
    		$titleFont = array_values($titleFontField)[0];
    	} else {
    		$titleFont = $pFont;
    	}
    ?>

    and the css:

    <style type="text/css">
    
    body {
    	font-family: "<?php echo $pFont; ?>" !important;
    }
    
    h1, h2, h3, h4, h5, h6 {
    	font-family: "<?php echo $titleFont; ?>" !important;
    }
    
    </style>

    there is following problem now though:
    I have a check box for the user to select a different font for titles. Then it shows the second google font select field and applies that font to titles. Otherwise, it just applies the first selected ‘p_font’. The problem is, even if only one font is selected, it still stores the second in the database and loads it up in the header of the page.

    Is there any way to get around this or control which fonts are being loaded?

    Thank you for your help and this awesome plugin ??

    Plugin Author danielpataki

    (@danielpataki)

    Hi wearevilla,

    The plugin doesn’t apply the font to any selector. The plugin is mostly meant for other developers to use and not for users to directly modify the set fonts of their themes.

    If I understand your solution, it works just fine, but there is an overhead of an extra font being loaded correct?

    I’m pushing out a new version which will allow you to modify the fonts being loaded via a hook, this should help you out ?? Keep an eye out in the Github Repo, I’ll push the update in an hour or so.

    Daniel

    I agree. I’m using this plugin to allow easy font selection in global themes and its working for the most part.

    Would be great to filter available font weights too, because it looks a little messy in the options page.

    May there is a way by feeding in a multi dimensional array?? I did, but it didn’t interpret it.

    public function google_font_list( $fonts ) {
    $fonts = array(
    ‘Raleway’ => ‘Raleway’,
    ‘Lato’ => ‘Lato’,
    ‘Oswald’ => ‘Oswald’,
    ‘Open Sans’ => ‘Open Sans’
    );

    return $fonts;

    Plugin Author danielpataki

    (@danielpataki)

    Hi @adam-ccrm,

    I’ve addressed this issue in the other thread, hopefully I can resolve it for you this week,

    Daniel

    Fantastic! Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ability to choose the css selector to apply font to…’ is closed to new replies.