• Resolved ShippeR

    (@shipper)


    Hello,
    originally, my problem is that I need change heading hrom <h2> to <h3>, which is hardcoded. So I have Child theme created and I already found what I need to change. For interest it’s hardcoded at file /generatepress_child/inc/theme-functions.php

    Could you change way of reguiring file at functions.php? You are using PHP function “require” and I would like you to change it to “require_once”. Consequently of this change I can load edited files in child theme and overwrite original one. Now I can’t because it will create conflict File already loaded.

    It’s change of code not only for me. It will help all people which want do only small edit in any file.

    Thank you for very good theme.
    ShippeR

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    While doing this would be useful is a few ways, it would also cause massive issues if we ever make changes/additions/removals in our theme-functions.php file. This would result in possible fatal errors, which wouldn’t be good.

    What exactly are you wanting to change in that file?

    Thread Starter ShippeR

    (@shipper)

    Hi Tom,
    function require_once is userfull for including PHP functions and classes because of it guards that file will not be loaded twice – second load of file with function of same name cause Fattal error.

    It makes sense to make change requiring of files what contain only functions. That will reduce cause of massive issues like you described.

    I don’t know if there is loading any other file with just functions. I know just what I inspected and there wasn’t much.
    In my case I would like to change line 90 of file functions.php to require_once $theme_dir . '/inc/theme-functions.php'; For my case it’s enought. I would like to follow first thought that solution should be as universal as it can be to help all others with edditing just small part of code if they needed.

    Best regards,
    ShippeR

    Thread Starter ShippeR

    (@shipper)

    My edit of code in file theme-functions.php is just changing of all heading type from <h2> to <h3> at function generate_get_the_title_parameters() because of styling.

    David

    (@diggeddy)

    Hi there,

    the theme is filled with Filter Hooks. So you shouldn’t need to overwrite the entire function. For that requirement you can use the generate_get_the_title_parameters filter like so:

    add_filter( 'generate_get_the_title_parameters', 'custom_archive_title_tag' );
    function custom_archive_title_tag( $params ) {
    
        if ( ! is_singular() ) {
            $params = array(
                'before' => sprintf(
                    '<h3 class="entry-title"%2$s><a href="%1$s" rel="bookmark">',
                    esc_url( get_permalink() ),
                    'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : ''
                ),
                'after' => '</a></h3>',
            );
        }
        return $params;
    }
    Thread Starter ShippeR

    (@shipper)

    Thank you very much!

    David

    (@diggeddy)

    You’re welcome

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Child theme and requiring at file functions.php’ is closed to new replies.