You can simply use the get_the_title()
function to get the current post’s title in your shortcode. If you want it to work only on pages, you can combine it with is_page()
:
function shortcode($atts) {
extract(
shortcode_atts(
array(
'name' => get_the_title(),
) ,
$atts)
);
// Rest of your code
}
add_shortcode('short_code', 'short_code');
You can use a PHP shorthand conditional as follows:
'name' => ( is_page() ) ? get_the_title() : 'Your else goes here' ;