Search code examples
wordpressgoogle-font-api

I want to add google fonts in function file of theme


I want to add fonts to my theme. So i have used the bellow code for this.

function load_fonts() {
            wp_register_style('et-googleFonts', 'http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,700,300');
            wp_register_style('et-googleFonts', 'http://fonts.googleapis.com/css?family=Helvetica:300italic,400italic,700italic,400,700,300');
            wp_enqueue_style( 'et-googleFonts');
        }
add_action('wp_print_styles', 'load_fonts');

So i have to use many fonts like Helvetica, Palatino and Trebuchet in the function. But i dont know how to add those fonts.


Solution

  • Try this

    function theme_assets() {
        wp_enqueue_style( 'et-googleFonts', "http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,700,300" );
        wp_enqueue_style( 'et-googleFonts1', "http://fonts.googleapis.com/css?family=Helvetica:300italic,400italic,700italic,400,700,300" );
    }
    
    add_action( 'wp_enqueue_scripts', 'theme_assets' );
    

    Also there must be wp_head() in your header file to make this work.!