- This topic has 10 replies, 2 voices, and was last updated 5 years, 9 months ago by Tom.
-
AuthorPosts
-
July 5, 2018 at 1:28 am #615907Lars Steen
Hello GP.
Im trying to override function in the plugin GP-premium:
/wp-content/plugins/gp-premium/page-header/functions/page-header.phpIn 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 actionadd_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
July 5, 2018 at 9:55 am #616353TomLead DeveloperLead DeveloperHi 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?
July 5, 2018 at 11:08 am #616430Lars SteenHello 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.
July 5, 2018 at 11:12 am #616440Lars SteenOrr snap. I guess the formsubmit ate some of my code.
http://take.ms/ORrD7 – here is a pic of the code.Br. Lars
July 5, 2018 at 9:32 pm #616848TomLead DeveloperLead DeveloperHmm, 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?
July 6, 2018 at 12:12 am #616896Lars SteenHello 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.
July 6, 2018 at 10:04 am #617459TomLead DeveloperLead DeveloperI’ll play with the new Page Hero code today (https://generatepress.com/gp-premium-1-7/). I should be able to filter the HTML π
July 6, 2018 at 10:19 am #617478Lars SteenHello 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.
July 6, 2018 at 11:03 am #617503TomLead DeveloperLead DeveloperI’ll write that article up today π
I also just made the Page Hero element filterable for beta.2.
July 7, 2018 at 3:11 am #617817Lars SteenHello Tom.
When will you push beta.2?Best regards. Lars.
July 7, 2018 at 9:54 am #618057TomLead DeveloperLead DeveloperI’ll be pushing it out on Monday π
-
AuthorPosts
- You must be logged in to reply to this topic.