在wordpress中传递数组中的php值
我有一个类似贝娄的功能在wordpress中传递数组中的php值,wordpress,function,Wordpress,Function,我有一个类似贝娄的功能 if(!function_exists('generate_share_urls')) { function generate_share_urls() { $title = the_title(); $content = the_content(); $share_urls = array ( 'facebook' => 'http://www.facebook.com/sharer/sharer.php?
if(!function_exists('generate_share_urls')) {
function generate_share_urls() {
$title = the_title();
$content = the_content();
$share_urls = array (
'facebook' => 'http://www.facebook.com/sharer/sharer.php?u=',
'twitter' => 'http://twitter.com/share?url=',
'google_plus' => 'https://plus.google.com/share?url=',
'linkedin' => 'http://www.linkedin.com/shareArticle?mini=true&url=',
'pinterest' => 'http://pinterest.com/pin/create/button/?url=',
'email' => 'mailto:?subject={'.$title.'}&body='.$content.',
'permalink' => ''
);
return $share_urls;
}
}
现在运行该函数时,我找不到页面的$title和$content。我的代码有任何错误。标题()
和内容()
将打印标题/内容,而不是返回。相反,您需要的是get\u
函数:
if(!function_exists('generate_share_urls')) {
function generate_share_urls() {
$title = get_the_title();
$content = get_the_content();
$share_urls = array (
'facebook' => 'http://www.facebook.com/sharer/sharer.php?u=',
'twitter' => 'http://twitter.com/share?url=',
'google_plus' => 'https://plus.google.com/share?url=',
'linkedin' => 'http://www.linkedin.com/shareArticle?mini=true&url=',
'pinterest' => 'http://pinterest.com/pin/create/button/?url=',
'email' => 'mailto:?subject={'.$title.'}&body='.$content.',
'permalink' => ''
);
return $share_urls;
}
}
从语法突出显示,他可能有一个未关闭的引用,以及在那里,不知道他只是复制它错误或是否真的是一个错误…谢谢你。我找到了我想要的。