Last active
July 5, 2021 13:18
-
-
Save noellesteegs/57bcd6909ff53192065c4af140201b42 to your computer and use it in GitHub Desktop.
Conditionally display a different logo based on page ID in Divi theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the function and pass the variable | |
function my_conditional_logo( $logo_container ) { | |
// Create a conditional statement to target specific page IDs | |
if( is_page( array( 1, 5, 9 ) { | |
// Create variable and set it to the path of the logo you'd like to display on these specific pages | |
$logo_url = '/wp-content/uploads/2021/07/my_logo_alt.svg'; | |
// If the conditional statement is false, use the default | |
} else { | |
// Update logo path to the default logo | |
$logo_url = '/wp-content/uploads/2021/07/my_logo.svg'; | |
} | |
// Set variable to match the HTML structure in Divi, but swap the image source for the $logo_url variable | |
$logo_container = '<div class="logo_container"><span class="logo_helper"></span><a href="/"><img src=" ' . $logo_url . ' " alt="My company logo" id="logo" width="173" height="62" data-height-percentage="54" data-actual-width="198" data-actual-height="71.3646"></a></div>'; | |
// Return variable to the server | |
return $logo_container; | |
} | |
// Run the custom function | |
add_filter( 'et_html_logo_container', 'my_conditional_logo' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment