• Resolved David_G

    (@questas_admin)


    Anyone know why this php snippet isn’t working after 4.3 upgrade? Any fix? I don’t want to use a plugin for fonts.

    add_action( 'wp_enqueue_scripts', 'my_google_font' );
    function my_google_font() {
        wp_enqueue_style( $handle = 'my-google-font', $src = 'https://fonts.googleapis.com/css?family=Playball|Dosis|Raleway|Orbitron|Tangerine', $deps = array(), $ver = null, $media = null );
    }

Viewing 15 replies - 1 through 15 (of 15 total)
  • It’s working for me. Can you post a link to a page that shows the issue?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What do you mean by not working; not enqueing?

    Thread Starter David_G

    (@questas_admin)

    OK I will change my statement.
    It is working on one site but not the other, both have the the same themes. Check out the footers.
    They both have the same css in the style sheet, both have the same enqueue snippet in the functions file. Both have child themes.

    Now I am wondering what I did wrong or causing the problem.

    Working Site

    Broken Site

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    So it’s not enqueing on the site that has the issue? Or that it’s not applying the style?

    Thread Starter David_G

    (@questas_admin)

    It’s not enqueing on the site, there are other places where I am using google fonts on that site but not working. The footer is common on both sites.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you remove the deps argument and other arguments after that to make sure the style isn’t dependent on anything? E.g.:

    add_action( 'wp_enqueue_scripts', 'my_google_font' );
    function my_google_font() {
        wp_enqueue_style( $handle = 'my-google-font', $src = 'https://fonts.googleapis.com/css?family=Playball|Dosis|Raleway|Orbitron|Tangerine' );
    }

    Thread Starter David_G

    (@questas_admin)

    #Andrew, what do you mean? Are you saying to remove all other code except this?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Oops no, I just mean removing this bit:

    , $deps = array(), $ver = null, $media = null

    So that your code results in this:

    add_action( 'wp_enqueue_scripts', 'my_google_font' );
    function my_google_font() {
        wp_enqueue_style( $handle = 'my-google-font', $src = 'https://fonts.googleapis.com/css?family=Playball|Dosis|Raleway|Orbitron|Tangerine' );
    }

    Thread Starter David_G

    (@questas_admin)

    OK I removed that, didn’t make a difference. hmmm.
    I will be offline for a couple hours, have to work.

    Thanks for the help

    Thread Starter David_G

    (@questas_admin)

    I found the problem, Somehow the functions.php file is getting all crammed together on the site instead of being line by line. Then my comments started with // and it commented out 2/3rd of my php. I copy and pasted directly to the WP theme editor and it’s fixed.

    Any idea why WP would do that?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Sounds like an issue with your hosting providers not understanding your line endings

    Thread Starter David_G

    (@questas_admin)

    When I look at my style sheet using the APPEARANCE editor, it is perfect, but the functions file is scrambled. They were uploaded by FTP not the cpanel file manager. I deleted the text in the editor and pasted directly to the WP editor it worked properly. I don’t see how it’s the hosting provider. I only have this problem with this one site not any others on the same host. And only with the functions, not the style. Is truly weird.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you replicate the issue? Try a different PHP file.

    Thread Starter David_G

    (@questas_admin)

    Yes, it’s easy, but I don’t want to take down the site to make it happen. It messed up other stuff. It’s working now. Funny it happened after the last update but didn’t affect my other sites. I am thinking about restoring back to an earlier backup and update it again. Seems like something is messed up with the update. 4.3

    Thread Starter David_G

    (@questas_admin)

    I quit quit using // to comment php also, using /* */ instead closes the comment line so then when it all gets run together it shouldn’t be an issue. That is what caused the problem when the code when to 2 lines.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘I cannot enqueue fonts’ is closed to new replies.