Dushyanth Kandiah
Dushyanth Kandiah

Reputation: 716

How to send page title as parameter in shortcode

How to get page title in to shortcode parameter's value? I have custom php script written which accepts parameters, I can send hard coded shotcodes in parameter as value but I have to send the page's title in parameter

Upvotes: 1

Views: 342

Answers (2)

izem
izem

Reputation: 413

Not sure that I understand your question, but to get the title of the current post use get_the_title(). You can use it within the shortcode function or when prepering the call for the custom php script you made.

https://developer.wordpress.org/reference/functions/get_the_title/

Upvotes: 0

Vasim Shaikh
Vasim Shaikh

Reputation: 4542

Send post title in shortcode :

[myshortcode title='Web pages']

// shortcode

function shortcode_myshortcode($atts) {

$atts = shortcode_atts(
        array(
            'title' => 'no foo',            
        ), $atts);

return  $atts['title'];

}
add_shortcode('myshortcode', 'shortcode_myshortcode');

Upvotes: 1

Related Questions