Support » Plugin: Code Snippets » Unload Google fonts — Genesis theme

  • Resolved detroitwidget

    (@detroitwidget)


    Hi Guys,

    I’m using the latest Genesis Sample theme with the Genesis Framework and I’m trying to unload (dequeue) the default Google font Source Sans Pro.

    The following code works fine when added to the bottom of the theme’s functions.php file, but does nothing when added as a Snippet:

    add_action( 'wp_enqueue_scripts', 'plp_dequeue_scripts_styles' );
    
    function plp_dequeue_scripts_styles() {
    
    wp_dequeue_style(
    		genesis_get_theme_handle() . '-fonts',
    		$appearance['fonts-url'],
    		array(),
    		genesis_get_theme_version()
    	);
    
    }

    Note:

    “fonts-url” is defined in a file named appearance.php in the child theme’s “config” directory. I suspect that’s why the code doesn’t work as a Snippet.

    Any ideas on how to fix this?

    Many thanks.

    WP Engine
    PHP 7.3
    WordPress 5.2.2
    Genesis Framework: 3.0.1
    Genesis Sample theme: 3.0.1
    Code Snippets: 2.13.3

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

    (@bungeshea)

    Hello,

    Are you able to post a sample of how you are defining the $appearance variable in appearance.php?

    If it’s defined as a global, then this might work:

    add_action( 'wp_enqueue_scripts', 'plp_dequeue_scripts_styles', 20 );
    
    function plp_dequeue_scripts_styles() {
    	global $appearance;
    
    	wp_dequeue_style(
    			genesis_get_theme_handle() . '-fonts',
    			$appearance['fonts-url'],
    			array(),
    			genesis_get_theme_version()
    		);
    	}
    }
    Thread Starter detroitwidget

    (@detroitwidget)

    Does this help (from child theme functions.php file)?

    add_action( 'wp_enqueue_scripts', 'genesis_sample_enqueue_scripts_styles' );
    /**
     * Enqueues scripts and styles.
     *
     * @since 1.0.0
     */
    function genesis_sample_enqueue_scripts_styles() {
    
    	$appearance = genesis_get_config( 'appearance' );
    
    	wp_enqueue_style(
    		genesis_get_theme_handle() . '-fonts',
    		$appearance['fonts-url'],
    		array(),
    		genesis_get_theme_version()
    	);
    
    	wp_enqueue_style( 'dashicons' );
    
    	if ( genesis_is_amp() ) {
    		wp_enqueue_style(
    			genesis_get_theme_handle() . '-amp',
    			get_stylesheet_directory_uri() . '/lib/amp/amp.css',
    			array( genesis_get_theme_handle() ),
    			genesis_get_theme_version()
    		);
    	}
    
    }
    Plugin Author Shea Bunge

    (@bungeshea)

    It does actually!

    Here’s an example which should work for removing that first script:

    add_action( 'wp_enqueue_scripts', function () {
    	$appearance = genesis_get_config( 'appearance' );
    
    	wp_dequeue_style(
    			genesis_get_theme_handle() . '-fonts',
    			$appearance['fonts-url'],
    			array(),
    			genesis_get_theme_version()
    		);
    	}
    }, 20 );

    Alternatively, if you wanted to remove all three which are enqueued in the function you posted, you could just stop the function itself from running:

    add_action( 'init', function () {
    	remove_action( 'wp_enqueue_scripts', 'genesis_sample_enqueue_scripts_styles' );
    } );
    Thread Starter detroitwidget

    (@detroitwidget)

    Hi Shea,

    The last two lines of your solution to remove the first script are generating a syntax error.

    Unfortunately, I don’t have any diagnostic skills. Any ideas?

    Thanks for your patience.

    Plugin Author Shea Bunge

    (@bungeshea)

    My apologies, looks like I made a mistaken when copying them over.

    Here’s a fixed version:

    add_action( 'wp_enqueue_scripts', function () {
    	$appearance = genesis_get_config( 'appearance' );
    
    	wp_dequeue_style(
    		genesis_get_theme_handle() . '-fonts',
    		$appearance['fonts-url'],
    		array(),
    		genesis_get_theme_version()
    	);
    	
    }, 20 );
    Thread Starter detroitwidget

    (@detroitwidget)

    That works. Thanks again for your help.

    Plugin Author Shea Bunge

    (@bungeshea)

    Great to hear! Thanks for reporting back.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Unload Google fonts — Genesis theme’ is closed to new replies.