- This topic has 6 replies, 2 voices, and was last updated 3 years, 2 months ago by
Ying.
-
AuthorPosts
-
February 13, 2023 at 8:47 am #2531744
Sean
Hi GP team,
On one of our GP sites, we would like to change the logo and background based on the month (so a Christmas theme in December, etc..). We found a solution for another theme that uses an action/function in the functions.php but the hooks are for the vantage-child theme.
https://wordpress.org/support/topic/auto-change-logo-and-background-image-every-month/
Are there variables in the GeneratePress theme that would be similar to those used in the code snippet below?
Thanks for any help you can provide!
–Sean
//auto change logo and masterhead background image depending on month add_action('init', 'update_logo'); function update_logo() { $month = date("n"); $my_fields = get_option('theme_mods_vantage-child'); if ($month == 12 || $month == 1 || $month == 2) { $logo = 7078; //christmas logo post ID $retina_logo = 7077; //christmas retina logo post ID $background = 'https://images2.luga.bg/2016/12/back_1080_christmas.jpg'; //christmas masterhead background image url address } else { $logo = 6979; //standard logo post ID $retina_logo = 6981; //standard retina logo post ID $background = 'https://images2.luga.bg/2016/12/back_1080.jpg'; //standard masterhead background image url address } $my_fields['theme_settings_logo_image'] = $logo; $my_fields['theme_settings_logo_image_retina'] = $retina_logo; $my_fields['vantage_page_masthead_background_image'] = $background; update_option('theme_mods_vantage-child', $my_fields); }February 13, 2023 at 11:37 am #2531960Ying
StaffCustomer SupportHi Sean,
Try this snippet for the logo, replace
your-holiday-logo-file-urlwith the actual logo url.add_filter( 'generate_logo_output','holiday_logo', 10, 2 ); function holiday_logo( $output, $logo ) { $month = date("n"); if ($month == 12 || $month == 1 || $month == 2) { printf( '<div class="site-logo holiday-logo"> <a href="%1$s" title="%2$s" rel="home"> <img width="999" height="999" class="header-image" src="%3$s" alt="%2$s" title="%2$s" /> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), esc_url( 'your-holiday-logo-file-url' ) ); } printf( '<div class="site-logo"> <a href="%1$s" title="%2$s" rel="home"> <img %3$s /> </a> </div>', esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), esc_url( apply_filters( 'generate_logo', $logo ) ) ); }As for the background, can you show us the background you are referring to?
February 13, 2023 at 12:04 pm #2532000Sean
The site is at https://www.theholidayhandbook.com/
and the background is the <body> background-image.
So, for example, for February we’d like to change the logo to https://www.theholidayhandbook.com/wp-content/uploads/2022/01/THH-February-finalpng.png
For the body background-image to this https://www.theholidayhandbook.com/wp-content/uploads/2021/12/THH-Background-Feb-1000×1000-1.png
Thanks SO MUCH for your help on this and let me know if there are any additional questions.
–Sean
February 13, 2023 at 12:26 pm #2532038Ying
StaffCustomer SupportHere’s the code for holiday background:
function holiday_background() { $month = date("n"); $cssToAdd = ""; if ($month == 12 || $month == 1 || $month == 2) { $cssToAdd = ' <style id="holiday-background"> body { background-image: url(https://www.theholidayhandbook.com/wp-content/uploads/2021/12/THH-Background-Feb-1000×1000-1.png) !important; } </style>'; } echo $cssToAdd; } add_action('wp_head', 'holiday_background');February 13, 2023 at 12:37 pm #2532049Sean
Thanks you SO MUCH! Worked like a charm. Appreciate your guidance.
–Sean
February 13, 2023 at 12:37 pm #2532050Sean
Closing the ticket.
February 13, 2023 at 6:03 pm #2532267Ying
StaffCustomer SupportNo Problem, glad to help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.