How to Dynamically Adjust the Launchpad Platform Custom Logo Link
This guide will help you customize the link of the custom logo on your Launchpad Platform WordPress site dynamically based on specific conditions. In this post, you learn how to modifies the logo link to direct users to the corresponding agency post, if the current page is a ‘rep_agency’ post or if specific URL parameters (‘agency_id’ or ‘agency_lid’) are present.
1. Access Your Theme’s Functions File
- To begin, log in to your WordPress admin dashboard.
- Next, navigate to the “Appearance” menu and select “Theme Editor.”
- In the right-hand panel, you’ll see a list of theme files. Find and click on the “functions.php” file associated with your currently active theme which are usually a child theme.
2. Insert the Provided Code
- Once you’ve opened the “functions.php” file, scroll to the bottom or a convenient location for adding custom code.
- This can also be done if you have installed code snippets plugin in your WordPress site like WPCode and Code Snippets to insert the code.
- Copy and paste the following code snippet into the “functions.php” file:
add_filter('hi_the_site_logo', function( $html ){
if( is_singular( 'rep_agency' ) || isset( $_REQUEST['agency_id'] ) || isset( $_REQUEST['agency_lid'] ) ) {
if( is_singular( 'rep_agency' ) ){
$agency_post_id = get_the_ID();
} elseif( isset( $_REQUEST['agency_lid'] ) ) {
$agency_lid = sanitize_text_field($_REQUEST['agency_lid']);
$agency_post_id = rep__get_agency_post_id( $agency_lid, 'agency_lid' );
} else {
$agency_id = sanitize_text_field($_REQUEST['agency_id']);
$agency_post_id = rep__get_agency_post_id( $agency_id );
}
if( $agency_post_id ){
$url = get_permalink( $agency_post_id );
$html = preg_replace('/href=["\'](.*?)["\']/', 'href="' . esc_url($url) . '"', $html);
}
}
return $html;
});
| This documentation provides a comprehensive guide for implementing and comprehending the provided code. You can further customize this code to adapt the logo behavior to different conditions or adjust the HTML attributes as per your specific requirements. |
3. Understanding the Code
- This code uses the
add_filterfunction to dynamically customize the link of the custom logo displayed in your Launchpad Platform WordPress site’s header by hooking the function tohi_the_site_logo. If you are using a basic theme or a theme that doesn’t have it own logo settings you can hook the function toget_custom_logo. - It checks specific conditions:
- If the current content is a single ‘rep_agency’ post.
- If either
agency_idoragency_lidis present in the URL parameters.
- Depending on the met condition, it identifies the URL to link the custom logo and updates the logo’s
hrefattribute accordingly.
4. Save Changes
After adding the code, click the “Update File” button (for themes) or save your plugin file to apply the changes.
5. Testing
To test the code, visit the pages or posts on your WordPress site that match the conditions specified in the code. You should see the custom logo’s link dynamically adjusted based on the content being displayed or URL parameters.