• I know a bit about HTML and CSS but I’m a novice when it comes to PHP.

    The thing is that I’m trying to heavily modify the Twenty Twelve theme to create a good-looking theme for my site.

    The test site is currently up at: https://test.techtage.com

    If I were editing the parent theme’s PHP files, the task would’ve been a lot easier for me. As I’m using a child theme, I’m facing a lot of limitations.

    I can’t seem to edit the function twentytwelve_fonts_url.

    Original code:

    function twentytwelve_get_font_url() {
    	$font_url = '';
    
    	/* translators: If there are characters in your language that are not supported
    	 by Open Sans, translate this to 'off'. Do not translate into your own language. */
    	if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
    		$subsets = 'latin,latin-ext';
    
    		/* translators: To add an additional Open Sans character subset specific to your language, translate
    		 this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. */
    		$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
    
    		if ( 'cyrillic' == $subset )
    			$subsets .= ',cyrillic,cyrillic-ext';
    		elseif ( 'greek' == $subset )
    			$subsets .= ',greek,greek-ext';
    		elseif ( 'vietnamese' == $subset )
    			$subsets .= ',vietnamese';
    
    		$protocol = is_ssl() ? 'https' : 'http';
    		$query_args = array(
    			'family' => 'Open+Sans:400italic,700italic,400,700',
    			'subset' => $subsets,
    		);
    		$font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
    	}
    
    	return $font_url;
    }

    What I tried adding in child theme’s functions.php:

    function twentytwelve_fonts_url() {
    	$fonts_url = '';
    
    	/* Translators: If there are characters in your language that are not
    	 * supported by Source Sans Pro, translate this to 'off'. Do not translate
    	 * into your own language.
    	 */
    	$source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'twentytwelve' );
    
    	/* Translators: If there are characters in your language that are not
    	 * supported by Bitter, translate this to 'off'. Do not translate into your
    	 * own language.
    	 */
    	$bitter = _x( 'on', 'Bitter font: on or off', 'twentytwelve' );
    
    	if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
    		$font_families = array();
    
    		if ( 'off' !== $source_sans_pro )
    			$font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
    
    		if ( 'off' !== $bitter )
    			$font_families[] = 'Bitter:400,700';
    
    		$query_args = array(
    			'family' => urlencode( implode( '|', $font_families ) ),
    			'subset' => urlencode( 'latin,latin-ext' ),
    		);
    		$fonts_url = add_query_arg( $query_args, "//fonts.googleapis.com/css" );
    	}
    
    	return $fonts_url;
    }

    I basically wanted the heading fonts of Twenty Thirteen. The above code not only doesn’t work, but renders the site unusable.

    Any idea? The other day I was messing up with Genesis child themes and I couldn’t most of the things of it as I practically have zero knowledge about PHP hooks, filters etc.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    The above code not only doesn’t work, but renders the site unusable.

    Which error message does it throw? You cannot redeclare a function?

    Thread Starter 008Rohit

    (@008rohit)

    Which error message does it throw? You cannot redeclare a function?

    Nothing. Just blank page. Neither the actual site nor WP-admin loads if I add that code in functions.php

    Don’t know if the code is faulty or Twenty Twelve has issues replacing functions from child theme.

    But if you’re a novice with PHP, you shouldn’t even be looking at the PHP files in the first place.

    At the end of your code, just below the right curly bracket, you’ve forgotten to add a line like add_action('init', 'twentytwelve_fonts_url');

    Thread Starter 008Rohit

    (@008rohit)

    Well, there was such a line in the original code, so like we mod custom style.css, I thought I only need to put the modified version of what I want to change.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP problems with Twenty Twelve (custom theme)’ is closed to new replies.