null, // Default value is null
'link' => 'no', // Default value is 'no'
'new_window' => 'no', // Default value is 'no'
'case' => 'default', // Default case option
'class' => '', // Default custom class
),
$atts,
'aio_page_title'
);
// Determine the page ID
$page_id = empty($atts['id']) ? get_the_ID() : absint($atts['id']);
// Get the title
$page_title = get_the_title($page_id);
// Apply case customization
switch ($atts['case']) {
case 'uppercase':
$page_title = mb_strtoupper($page_title);
break;
case 'lowercase':
$page_title = mb_strtolower($page_title);
break;
case 'capitalize':
$page_title = ucwords(mb_strtolower($page_title));
break;
case 'sentence':
$page_title = ucfirst(mb_strtolower($page_title));
break;
case 'first':
$page_title = ucfirst($page_title); // Capitalizes only the first character
break;
default:
$page_title = $page_title; // Leave as is
break;
}
// Add link if specified
if ($atts['link'] === 'yes') {
$target = $atts['new_window'] === 'yes' ? ' target="_blank"' : '';
$page_title = '' . esc_html($page_title) . '';
} else {
$page_title = esc_html($page_title);
}
// Add custom class if specified
$class_attribute = !empty($atts['class']) ? ' class="' . esc_attr($atts['class']) . '"' : '';
// Wrap in a span with optional class
return '' . $page_title . '';
}
add_shortcode('aio_page_title', 'aiosc_page_title_shortcode');