• Hi,

    I’m a confirmed web designer, write html and css very well, and copy and paste / edit js and php when needed. I regularly build custom WordPress sites, and use functions.php (very succesfully) to modify WordPress’s behavior.

    I’m currently building a site with Twenty Twenty Three, I struggled to get my child-theme to function, using code snippets functioning on previous sites I’ve built, and numerous copy-pastes found online, eventually this one worked :

    <?php
    
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        $parenthandle = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
        $theme = wp_get_theme();
        wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css', 
            array(),  // if the parent theme code has a dependency, copy it to here
            $theme->parent()->get('Version')
        );
        wp_enqueue_style( 'child-style', get_stylesheet_uri(),
            array( $parenthandle ),
            $theme->get('Version') // this only works if you have Version in the style header
        );
    }

    I’ve kept this site ultra simple and could just about get away without using functions.php for modifying the layout, however it would be nice and also I don’t like not understanding whats going on ^^

    So whenever I add a snippet after the child-theme snippet, the whole site crashes…

    Is there a problem in this snippet ? Am I doing something wrong ?

    Thanks !

    • This topic was modified 1 year, 2 months ago by bcworkz. Reason: true URL from URL shortener

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sam1351

    (@sam1351)

    Here’s an example with an extra snippet :

    <?php
    
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        $parenthandle = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
        $theme = wp_get_theme();
        wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css', 
            array(),  // if the parent theme code has a dependency, copy it to here
            $theme->parent()->get('Version')
        );
        wp_enqueue_style( 'child-style', get_stylesheet_uri(),
            array( $parenthandle ),
            $theme->get('Version') // this only works if you have Version in the style header
        );
    }
    
    function the_post_thumbnail_caption( $post = null ) {
        /**
         * Filters the displayed post thumbnail caption.
         *
         * @since 4.6.0
         *
         * @param string $caption Caption for the given attachment.
         */
        echo apply_filters( 'the_post_thumbnail_caption', get_the_post_thumbnail_caption( $post ) );
    }

    Hey, sam1351, do you have the associated PHP error with the crash available to post?

    Thread Starter sam1351

    (@sam1351)

    Hi Ian,

    No… Critical Error is the only info I have. I’ll leave the site crashed for 15 minutes if you’re around you can take a look.

    Moderator bcworkz

    (@bcworkz)

    @sam1351 — please do not use URL shorteners in these forums. For safety reasons we like to see where URLs are taking us. The “Page I need help with” field is only visible to logged in members, it’s not visible to search bots. There is little reason to use an URL shortener service here.

    I took the liberty changing the field to it’s proper URL. If this is unacceptable for any reason the field can be blanked instead. But then it may be more difficult for anyone to help you. To have the field blanked, use the topic’s Report button (in sidebar, or below on mobile). Pick the “Other” reason. Explain that bcworkz changed the URL without asking you first and request the field be blanked.

    When you get that generic critical error message, a more detailed message should be available in your server’s error log.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘functions.php breaking site when I add custom code’ is closed to new replies.