我編碼一個插件,我用簡短的代碼,以呈現頁面內容更改頁面標題。我想更改頁面標題。我用這個:用一小段代碼
// Change the title of the page of the charts to add the current month.
add_filter('the_title', 'charts_title', 10, 2);
function charts_title($title, $id) {
$title .= ' ' . date('F Y');
return $title;
}
但它是這樣做的所有職位和頁面。我可以只爲包含我創建的短代碼的頁面做到這一點嗎?我試圖做到這一點,但它不起作用。
add_shortcode('charts-vote', 'charts_vote');
function charts_vote($atts) {
// Add the filter only in the short code function callback.
add_filter('the_title', 'charts_title', 10, 2);
// ... //
return $content;
}
有人能幫我嗎?
你的簡碼呈現。一般來說,這就是短代碼的工作方式。也就是說,它們在'the_content'運行時渲染。這將是棘手的。 – 2013-03-09 15:59:54