• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to add snippets to files

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › How to add snippets to files

This topic is: not resolved

Tagged: snippets, tutorials

  • This topic has 1 reply, 2 voices, and was last updated 8 years, 2 months ago by Victor Font.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • September 10, 2015 at 5:19 pm #165176
    brindamair
    Participant

    Hello everyone:
    I understand the usefulness of snippets but there is no clear instructions on their website on how to add such to functions.php.
    They can not go anywhere. It is evident, but you only indicate "add to functions.php or footer.php, etc", no more.
    I do not want to use plugins.

    This happens to me every time I want to add a snippet.
    I read everything I find on the subject, without success.

    For example, when I add the snippet of gravatar
    **********************
    add_filter ('avatar_defaults' 'sp_gravatar');
    sp_gravatar function ($ avatar) {
    $ Custom_avatar = get_stylesheet_directory_uri (). '/images/gravatar.png';
    $ Avatar [$ custom_avatar] = "Custom Gravatar";
    return $ avatar;
    ****************************
    YOUR instructions: add to functions.php. This is not enough for beginners
    I tried elsewhere in functions.php but my website disappears

    Can I get some more precise instruction for add snippets without breaking my website (altitude pro) or should I continue betting to luck?
    Obviously I'm not webmaster. I'm just a trainee with very good disposition and I trust StudioPress and Genesis but you speak for webmasters.

    I think this problem would find a solution with a tutorial showing precisely where to include the snippet in the file. If this tutorial already exists, as I find it.

    Thank you
    Graciela

    http://canalizandoluz.com.es
    September 10, 2015 at 5:55 pm #165179
    Victor Font
    Moderator

    PHP is a very unforgiving language. If you even have 1 incorrect character, it can take down your site. The code you have above is all wrong. The snippet code on the Studio Press works if you cut and paste it into functions.php. It doesn't matter where it goes in functions.php, but it does have to be copied exactly as it is written. In the code above you've transposed the function name and function declaration. You have curved quotes instead of straight quotes. You have a space before the $ and variable name and in some cases you've capitalized variable names and used them as lower case later on. This makes them two different entities.

    Learn how to cut and paste the code exactly as it is presented and you won't have problems.

    //* Display a custom Gravatar
    add_filter( 'avatar_defaults', 'sp_gravatar' );
    function sp_gravatar ($avatar) {
    	$custom_avatar = get_stylesheet_directory_uri() . '/images/gravatar.png';
    	$avatar[$custom_avatar] = "Custom Gravatar";
    	return $avatar;
    }

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble