enqueue Google-fonts link in function.php

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Johannes davidian

johannes davidian

28/11/2016 11:57:46
Quote Anchor link
hallo,

ik heb in mij function.php bestand deze code ingevoerd :

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
function auto_repair_scripts() {
      //add Google fonts Merriweather
wp_enqueue_style( 'auto-repair-google-fonts, 'https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i' );

maar ik krijg foutmelding.
normaal gesproken de link is :<link href="https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i" rel="stylesheet">

ik kan deze link in header.php toevoegen maar ik wil het enqueue in function.php en het moet kunnen.

een deel van mij function.php code is:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function auto_repair_stylesheets() {
    wp_register_style( 'style.css',  get_template_directory_uri() . '/style.css', array(), null, 'all' );
    wp_register_style( 'app.css',  get_template_directory_uri() . '/app.css', array(), null, 'all' );
    wp_enqueue_style( 'style.css' );
    wp_enqueue_style( 'app.css' );
  
}
add_action( 'wp_enqueue_scripts', 'auto_repair_stylesheets' );

/**
 * Enqueue scripts and styles.
 */
function auto_repair_scripts() {
      //add Google fonts Merriweather
wp_enqueue_style( 'auto-repair-google-fonts, 'https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i' );
    wp_enqueue_script( 'auto-repair-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );

    wp_enqueue_script( 'auto-repair-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );


hoe ik kan deze probleem oplossen?

dank u wel
Johannes
 
PHP hulp

PHP hulp

24/04/2024 04:05:43
 
- Ariën  -
Beheerder

- Ariën -

28/11/2016 12:06:10
Quote Anchor link
Gokje: Zet eens een ' na auto-repair-google-fonts.
 
Johannes davidian

johannes davidian

28/11/2016 12:18:55
Quote Anchor link
dank U wel,
ik heb het deze code (auto-repair-google-fonts) in de voorbeeld boven function.php:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
wp_enqueue_style( 'auto-repair-google-fonts, 'https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i' );

het helpt niet auto_repair-google-fonts of auto-repair-google-fonts
johannes
 
- Ariën  -
Beheerder

- Ariën -

28/11/2016 12:20:36
Quote Anchor link
Wat gebeurt er dan precies? Je hebt het over een error. Maar welke dan precies?
 
- SanThe -

- SanThe -

28/11/2016 12:26:25
Quote Anchor link
Johannes davidian op 28/11/2016 12:18:55:
ik heb het deze code (auto-repair-google-fonts) in de voorbeeld boven function.php:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
wp_enqueue_style( 'auto-repair-google-fonts, 'https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i' );

En daar mist nog steeds de enkele quote.
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
wp_enqueue_style( 'auto-repair-google-fonts', 'https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i' );
 
Johannes davidian

johannes davidian

28/11/2016 12:27:24
Quote Anchor link
ik krijg deze melding:

parse error: syntax error, unexpected 'https' (T_STRING) in /mnt/web010/b0/48/56990848/htdocs/WordPress_SecureMode_01/wp-content/themes/auto-repair/functions.php on line 130

en de code in lijn 130 is :

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
wp_enqueue_style( 'auto_repair-google-fonts, 'http://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i' );


johannes
 
- SanThe -

- SanThe -

28/11/2016 12:30:41
Quote Anchor link
Missing quote dus.
Zie boven.
 
Johannes davidian

johannes davidian

28/11/2016 13:27:53
Quote Anchor link
Dank U wel ,
U heb gelijk.

maar na invoeren deze font family style (Merriweather) in CSS als volgende:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
html {
    font-family:'Merriweather', serif;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust:     100%;
}


en
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
body,
button,
input,
select,
textarea {
    color: #404040;
    font-family: 'Merriweather', serif;
    font-size: 16px;
    font-size: 1rem;
    line-height: 1.5;
}


Het letters style veranderd niet naar Merriweather style.

Mij function.php code is nu als volgende:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
 * Register style sheet.
 */
function auto_repair_stylesheets() {
    wp_register_style( 'style.css',  get_template_directory_uri() . '/style.css', array(), null, 'all' );
    wp_register_style( 'app.css',  get_template_directory_uri() . '/app.css', array(), null, 'all' );
    wp_enqueue_style( 'style.css' );
    wp_enqueue_style( 'app.css' );
  
}
add_action( 'wp_enqueue_scripts', 'auto_repair_stylesheets' );

/**
 * Enqueue scripts and styles.
 */
function auto_repair_scripts() {
      //add Google fonts Merriweather
 
wp_enqueue_style( 'auto-repair-google-fonts', 'https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i' );
    wp_enqueue_script( 'auto-repair-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );

    wp_enqueue_script( 'auto_repair-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'auto_repair_scripts' );


ik heb voor zekerheid de brouwser data gewist maar toch het probleem blijft hetzelfde de letters veranderd niet naar Merriweather!

wat kan het probleem zijn nu . is het probleem ligt in function.php code of ergens anders?

johannes
 
Ozzie PHP

Ozzie PHP

28/11/2016 13:33:36
Quote Anchor link
Zet helemaal bovenin je css bestand eens het volgende:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
@import url("https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i");
 
Johannes davidian

johannes davidian

30/11/2016 11:32:21
Quote Anchor link
Dank U wel iedereen,
ik was ziek 2 dagen daarom ik heb geen reactie gegeven.
het fout was in underscores-thema zelf ,soms doet deze Wordpress thema rare dingen,mischien wordpress zelf doet soms rare dingen.

ik heb nieuwe thema geinstalleerd en de Google-fonts link ingevoerd in header.php :
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
/**
 * The header for our theme.
 *
 * This is the template that displays all of the <head> section and everything up until <div id="content">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Garage
 */


?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<!-- Compressed CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/foundation/6.2.4/foundation.min.css">
<?php wp_head(); ?>
</head>

het kan ook via importen in css bestand :
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
@import url("https://fonts.googleapis.com/css?family=Merriweather:400,400i,700,700i");


en derde manier is enqueue de Google-fonts in functions.php als volgende:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
function load_fonts() {
            wp_register_style('googleFonts', 'http://fonts.googleapis.com/css?family=Rock+Salt|Neucha');
            wp_enqueue_style( 'googleFonts');
        }
    
    add_action('wp_print_styles', 'load_fonts');


de url voor hoe U kunt Google-fonts invoeren in Wordpress thema is :https://webdesignfromscratch.com/wordpress/using-google-web-fonts-with-wordpress-the-right-way/

dank u wel iedereen
Johannes
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.