[Support request] Override function in GP-premium page-header.php in child theme

Home Forums Support [Support request] Override function in GP-premium page-header.php in child theme

Home Forums Support Override function in GP-premium page-header.php in child theme

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #615907
    Lars Steen

    Hello GP.

    Im trying to override function in the plugin GP-premium:
    /wp-content/plugins/gp-premium/page-header/functions/page-header.php

    In line 15 there is if ( ! function_exists( ‘generate_page_header_area_start_container’ ) ) …

    I tried to put the function:
    function generate_page_header_area_start_container( $image_class, $content_class ) {…

    In child functions.php file, but i get 500 error because the function already exists.
    I guess it something with load-order, så i tried to put it inside an action

    add_action(‘plugins_loaded’, ‘runthisfirst’, 0);
    function runthisfirst() {
    function generate_page_header_area_start_container( $image_class, $content_class ) {…
    }

    I tried to make a mini plugin to see if that helps, so i can override the function in this way, but with no luck also.

    I guess i’m doing something wrong.

    Can you please help to tell how i can override the function “generate_page_header_area_start_container”

    Best regards. Lars

    #616353
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I don’t suggest doing this, as you’ll miss any changes we make to the function in the future, which can cause errors.

    What about the function are you trying to change?

    #616430
    Lars Steen

    Hello Tom.

    I would like to do it via hooks.
    But I have no hooks to do it with.

    I want to lazyload the header image.

    I’m using blazyload.js.
    This means that I need to add class “b-lazy” to the header div plus “data-src=”[image.jpg]””: <div id=”page-header- … class=”… b-lazy” .. data-src=”[image.jpg]”

    I did this in a small plugin and it’s working:
    add_action( ‘activated_plugin’, ‘aprt_plugin_load_first’ );
    function aprt_plugin_load_first() // make this plugin run first.
    {
    $path = str_replace( WP_PLUGIN_DIR . ‘/’, ”, __FILE__ );
    if ( $plugins = get_option( ‘active_plugins’ ) ) {
    if ( $key = array_search( $path, $plugins ) ) {
    array_splice( $plugins, $key, 1 );
    array_unshift( $plugins, $path );
    update_option( ‘active_plugins’, $plugins );
    }
    }
    }
    And then in the small plugin i override “generate_page_header_area_start_container()” and do the following changes from line 100 in the plugin header file:

    printf(

    ‘,
    ( ‘fluid’ == $options[ ‘container_type’ ] ) ? $video : null,
    $content_class . $parallax . $full_screen . $vertical_center_container . $container_type . $combined_content . ‘ generate-page-header generate-content-header’,
    ( ‘fluid’ !== $options[ ‘container_type’ ] ) ? $video : null,
    $vertical_center,
    ( ” !== $options[ ‘merge’ ] ) ? ‘generate-merged-header’ : ”,
    ( ! empty( $parallax ) ) ? ‘data-parallax-speed=”‘ . esc_attr( $parallax_speed ) . ‘”‘ : ”,
    $options[ ‘page_header_id’ ],
    $blazy_class_if_image = (!empty($image_url)?’ b-lazy’:”),
    $blazy_src_image = (!empty($image_url)? ‘ data-src=”‘.$image_url.'”‘:”)

    );

    Changes:
    s%8$ and s%9$
    $blazy_class_if_image = (!empty($image_url)?’ b-lazy’:”),
    $blazy_src_image = (!empty($image_url)? ‘ data-src=”‘.$image_url.'”‘:”)

    If you have a better way to do it, i would really like to hear. I need lazyload 🙂

    Best regards. Lars.

    ps. For the dynamic css outputting the background-images. I string regex replaced it.

    #616440
    Lars Steen

    Orr snap. I guess the formsubmit ate some of my code.
    http://take.ms/ORrD7 – here is a pic of the code.

    Br. Lars

    #616848
    Tom
    Lead Developer
    Lead Developer

    Hmm, so that’s to lazy load the background image? The Page Header is at the top of the page though, so wouldn’t the loading happen immediately as the user loads the page?

    #616896
    Lars Steen

    Hello Tom.

    Yes I totally want to change the load order of the top header image, to move it for after first load.
    This is, and will feel like a speedboost specially on mobile.

    With this change, I can also control animation in the header text in relation to headerimage (if needed) – And make a delicious entrance effect 🙂

    I know this is kinda last resort, with the first load plugin thing. It would be awesome if GP at least could make a filter hook, so i could control the html before it’s output to the frontend. Doing that would make the output very flexible in relation to all manipulation of the header – In my opinion of cause 🙂

    I really like that GP did not hold back in action and filters across all the other code. Thank you for this.

    Best regards. Lars.

    #617459
    Tom
    Lead Developer
    Lead Developer

    I’ll play with the new Page Hero code today (https://generatepress.com/gp-premium-1-7/). I should be able to filter the HTML 🙂

    #617478
    Lars Steen

    Hello Tom.

    Thanks for sharing.

    I see a lot of features that I would like that suddenly is there in the “elements” module.
    The hook part is also nice, it’s gonna reduce time building websites on the theme even more.

    Reducing build time is why I choose go GP.

    I was just playing around with the video background image feature.
    I kindly ask you to share the article of how to build with elements.

    I kind of already know what to do, but it would be nice to see, how you would build it.

    Thanks for your reply.

    #617503
    Tom
    Lead Developer
    Lead Developer

    I’ll write that article up today 🙂

    I also just made the Page Hero element filterable for beta.2.

    #617817
    Lars Steen

    Hello Tom.
    When will you push beta.2?

    Best regards. Lars.

    #618057
    Tom
    Lead Developer
    Lead Developer

    I’ll be pushing it out on Monday 🙂

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.