Last active
October 19, 2023 06:48
-
-
Save humayunahmed8/38c29000d4024c1b0189d8e0e2aecb78 to your computer and use it in GitHub Desktop.
Conditional url type selector with codestar metabox framework
Author
humayunahmed8
commented
Oct 19, 2023
<?php
// **Without custom link value check. In that case, If select "WordPress Page" => "_self" / Custom URL => "_blank" / By Default "_self"**
// Banner Button URL
$button_url_type = isset($lhcorp_section_meta['button-url-type']) ? $lhcorp_section_meta['button-url-type'] : 'same_tab';
if ('same_tab' === $button_url_type && !empty($lhcorp_section_meta['button-link-wp-page'])) {
// Use WordPress page URL
$button_url = get_permalink($lhcorp_section_meta['button-link-wp-page']);
$link_target = '_self'; // Open in the same tab
} elseif ('new_tab' === $button_url_type && !empty($lhcorp_section_meta['button-link-custom-url'])) {
// Use custom URL
$button_url = esc_url($lhcorp_section_meta['button-link-custom-url']);
$link_target = '_blank'; // Open in a new tab
} else {
// Default to a fallback URL or do something else based on your requirements
$button_url = '#';
$link_target = '_self'; // Open in the same tab
}
// Check if the key 'button-label' exists in the array
$button_label = isset($lhcorp_section_meta['button-label']) ? esc_html($lhcorp_section_meta['button-label']) : '';
?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment