Search Results for 'child theme how to functions.php'

Results from the Forum
simchris
tagDiv Member

Gotcha – makes sense to me 🙂

Probably explains why the custom functions didn’t work for me one our two test sites.

I switched one from using child theme to only use parent (since Google doesn’t like the CSS redirect, for their own peculiar reasons) and simply edited the parent functions.php to put my custom functions at end (like changing compression rate for images, removing excess css publication, etc.).

Hopefully this will be addressed soon for those using child theme for mods.

gaston
tagDiv Member

Thanks @Christopher, but it doesn’t work for us, because the call is already defined on the parent functions.php and if we add it to the child functions.php the site breaks.

What we read around different forums is that the parent function has to be programmed conditionally and not load if it exists on the child theme that’s the code we’ll need to change and also be added to the new version.

Best,

simchris
tagDiv Member

The “normal” way to do this is to add the call to your child theme folder functions.php to pull the js from your child theme directory vs the parent directory.

http://wordpress.org/support/topic/how-to-add-js-files-to-child-theme

Ulmi
tagDiv Member

Thx, I’ve implemented it in the functions.php of the child theme:

function child_theme_setup() {
    add_image_size( 'art-wide', 326, 219, true );
}
add_action( 'after_setup_theme', 'child_theme_setup', 11 );
simchris
tagDiv Member

Ooops: one more.

For those who are testing for speed-speed-speed and want to fix all their “you could optimize image xyz” warnings. I actually wrote an article on this once upon a time on my old site no longer seen anywhere since it was behind a login.

BASICALLY:
1) backup all your images
2) install the wp regenerate thumbnails plugin
3) check your wp settings > media and make sure the S / M /L sizes match what is being used by theme so you don’t end up with more thumbs than needed (seriously this is the #1 mistake folks make with thumbnails in general)
4) add the following code to your functions.php file in the theme root at the end –or– in your child theme (TIP: stop using a child theme)
add_filter( 'jpeg_quality', create_function( '', 'return 50;' ) );
5) run the regenerate thumbnails plugin under wp admin > tools

Voila!~ go rerun your speed test with Google and magically no more “you need to optimize image xyz to save 5kb” crap.

If your images don’t look as sparkly as they did, you can always delete the thumbs, put your original images back, and then try changing the “50” to “60” if you prefer.

For all those thumbnails all over the place “50” is recommended setting, and this uses both the built-in function of wordpress for images which hooks into the image mod stuff on the server. UPSHOT: when you make this change to your functions.php file – ALL YOUR FUTURE IMAGE THUMBS will be compressed automatically.

No more extra plugin to do that unless you really want to.
Simple. Easy. Quick.

Sandall
tagDiv Member

Thank you Christopher for your suggestion.
I have activated Newspaper child theme, but it broke page CSS. Maybe, I did something wrong?
So, first, I uploaded Newspaper-child folder with style.css and functions.php files in it, into themes directory on web site. Than I navigated to Themes and activate Newspaper-child theme. Am I wrong?

Marius, i have set you a mail regarding this issue.

Thanks you for support.

Sandall

simchris
tagDiv Member

vidapropria
1) reduce image sizes either by running compression plugin and/or adding compression factor to your functions file
2) faster server account, if you keep seeing “slow response from server” error — that was a [!] item on your last report speed check — nothing can be done about that with the theme, or in WP; that is how fast the account you have and your hosting provider is responding to ping/start showing the page. For example if you have a $5/month account, upgrade to $10/month account (I’m just using that as example). Low cost accounts are usually on a machine or VPS being shared with 1,000+ other sites. Slightly more costly hosting accounts give more resources to each site, by sharing the resource pool with fewer domains.

Verify deflate/gzip working; remember this only serves up faster versions of your content, but doesn’t optimize them prior to that. I think I saw a 100K image file in your last report … that is waaaaaaaaay too big. Try using smushit plugin and regenerate thumbnails to see if that helps? (Backup images first as changes to images on server will be destructive — meaning they are changed and cannot be unchanged).

Also, for testing if you’re using a child theme, be sure to try NOT using a child theme to see if that gains you a point.

However RECOMMENDED:
1) optimize images before/after upload
2) look at better hosting – if you keep getting “slow to respond” error from Google — no way around that on your side.
3) test without using DISQUS, as this does slow things down. We stopped using it for that reason. We’re leaning toward phasing out comments on most sites, per industry practice now that most comments tend to be trolls and arguments (see: CNN for example). Any comments plugin really slows stuff down on WP. Unless you gain ad revenue from 10,000 visitors per day, it’s not really an essential plugin, and more of a glamour thing (in my opinion).
4) turn off all jetpack stuff for speed test — anything that connects to the WP/Automattic mothership adds latency.

Hope that helped 🙂

————–
as an aside on pagespeed errors:
I’m actually dealing with even more arcane stuff like how to enqueue the parent Theme’s style sheet in the child Theme’s functions.php, to bypass the annoying @import not recommended error from Google which the Automattic folks seem to think is a non-issue. I will post my efforts on THAT noise if anybody cares.

[ UPDATED ]
I just ran your GPS test, and saw you’re up to 82/100 desktop. So, looks like you’re making progress. The images issue is the next thing you need to resolve. You’ll have several points for that, as reducing the footprint of your images speeds up page (e.g., if you go from 300K to 150KB; that’s 50% less time loading images!).

For the minification stuff… note you would need to use a plugin for that (WPminify) although this has some issues; -or- you need to manually minify SOME resources which are not already reduced in size. RADU doesn’t minify all the code as developers have a hard time modifying code if they can’t read it.

So, if you knew there were a couple of large CSS/JS files you might want to minify, you can easily do that using an online tool (I use this one, although it won’t work with IE11/Win7 properly … use Chrome or similar: http://refresh-sf.com/yui/ )

Basically, “minification” of CSS and Java/js files removes the extra spaces, comments, and line breaks to make file “more compact” … so if you had a 125Kb CSS file, by removing all the spaces, line breaks, comments, it might end up being 100Kb, which is the kind of reduction that PageSpeed looks at — the idea being if you had 5 files being loaded on page and you reduced all of them by 20kb – well, that’s 100Kb and is larger than what website developers like me used for the entire page and graphics 10 years ago (we used to shoot for 50kb max page load, if you can imagine that!) …

  • This reply was modified 12 years by simchris.
simchris
tagDiv Member

Just fyi on web fonts …
since the fonts are being loaded from Google’s CDN, there isn’t really any way to “optimize” Google’s loading of those fonts in the way some of you may think – how can the theme optimize something living on Google’s CDN ?. Although “technically” one might remove the &ver=3.71. for some very minor compliance in moving away from that kind of versioning data in WP.

How we did it on our static main business site (not running WP except for news and blog areas, but it’s the same concept in how you might “super optimize” YOUR setup), was we downloaded the equiv fonts (Open Sans family), created style sheet, uploaded both CSS and fonts to our own CDN (S3/CloudFront), setup CORS rules, and now load the fonts off of Amazon’s cloud where we could set expiration times of one year, and compress, etc. In our case we did it both to control all the font parameters for PageSpeed and also the whacky bug in IE for not loading the true italic version of fonts off Google’s CDN without manually inserting calls to all font versions one at a time for IE which results in loading 8 font families per page). Using a custom style sheet to load all the fonts, we load just ONE file for the reg/reg italic, bold/bold italic and solve two issues with Open Sans.

For “most” people you need to setup your compression, and time to live (expiration headers) on YOUR end of things before anything else – that is not a function of the theme. Google how to do that, or contact your hosting provider. Then move on to the other stuff. As GZAM pointed out, and as I have previously, the compression and expiration headers alone account for about 20 points or more in Google Page Speed.

Fonts are a tricky bit, where any “designer” fonts, slow down page regardless, as they have to be loaded from somewhere. For those looking for “fastest speed” once everything else is done, you might have to NOT use custom fonts at all, and sub out Trebuchet MS for the menus, and something like Georgia or Arial/Helvetica for the body text.

Spending the $2 a month for Amazon’s CDN (or similar) is one way to speed up your fonts, vs loading them from Google directly, but that is something you need to try, modify, test, modify, test. For example, we use Font Awesome, and we tested loading that off the cloudflare hosted version vs our CDN on Amazon – Amazon was faster so we load that from there.

Not sure if any of that helps. It is a process, not a one click thing to optimize a page for ‘speed’ — there is NO “one click” solution out there due to complexity of servers, content, and everything being loaded on the page.

For example on optimization — if you want faster speed, what about image compression level using built in functions of wordpress? Did you know you can use a plugin or function to increase the compression level of the thumbnails appearing on the pages? Smaller files there make page load faster even before server side gzp/deflate. These are the kinds of things you need to research if trying to optimize your site for fasted load times.

For example, you could set the compression of images to something like 60% or even 50% in your child theme functions.php … will only change level on new images uploaded unless you use the regenerate thumbnails plugin or similar.

add_filter( 'jpeg_quality', create_function( '', 'return 50;' ) );

I’m not sure what Radu has the quality set to by default, but increasing the compression even 10% from the default improves speed.

Additional ref:

switch ( $mime_type ) {
 case ‘image/jpeg’:
return imagejpeg( $image, $filename, apply_filters( ‘jpeg_quality’, 90, ‘edit_image’ ) );
case ‘image/png’:
return imagepng( $image, $filename );
 case ‘image/gif’:
return imagegif( $image, $filename );
 default:
 return false;
 }

Google’s webpagetest.org actually recommends quality level 50 for web images.

We are shooting for “60” at the moment (60/100 compression is not percentage of compression, btw).

  • This reply was modified 12 years by simchris.
  • This reply was modified 12 years by simchris.
  • This reply was modified 12 years by simchris.
dalandau
tagDiv Member

What does this mean

1. Child themes are partially supported. You can override the css and the template files. You can’t override our code.

what can I override, what can’t I, I do not understand

can I use child theme for?

functions.php

/wp-content/themes/Newspaper/includes/app/modules/module_modifier/td_module_blog.php

/wp-content/themes/Newspaper/includes/content_builder/td_module.php

simchris
tagDiv Member

HI … just to clarify I’m not misunderstanding:

the functions.php in child theme should over-ride core WP functions as normal – correct? But may not over-ride “theme specific” functions.

I think I can live with that (whew) 🙂

simchris
tagDiv Member

We also need the functions in child theme to work.
This is mandatory to enable custom over-rides for the site, turn off functions in things like Yoast for the menubar, specify custom optimizations, etc.

Child theme functions.php must be enabled for this theme to propagate both professionally and for the WordPress community to support it – period.

This includes over-rides for removing “versions” on javascript and CSS and font calls, removing RSS enclosures, removing error messages at login hack attempts, changing the WP post revisions interval and numbers, etc., etc.

This is one of the core functions (pun intended) for having a child theme.

This may mean looking for another theme provider, after all, if this core function support is removed. I’m already having to do couple of hacks on every version for things still not fixed, and which are *still* not yet defaults (like author byline on post … why should this be optional by a hack?).

C’mon folks. Time to clean up some of the BASE LINE functions of the theme before getting too tricky with some of the other stuff with galleries, or sliders, or whatnot.

mibrahim_folio3
Participant
#0

Hi, Not sure if we can overwrite function in Newspaper/functions.php by using child theme as functions in Newspaper/functions.php are declared without “if ( ! function_exists(“.

What do you suggest if we cant to change functionality of any function.
Thanks

simchris
tagDiv Member

I would also recommend adding a folder called /mods/ in your root for the theme, and put backups of your mod files there (meaning the files you make mods to – put the MODIFIED versions in there). This is a handy reminder when you go to do a manual update via FTP, to go “oh. duh. I need to over-write the new files with my mod files…”

Obviously, child theme support for these elements via functions.php would be preferable, but I haven’t gotten that far.

  • This reply was modified 12 years by simchris.
Viewing 13 results - 626 through 638 (of 638 total)