![](/img/trans.png)
[英]How can i call a plugin shortcode from within a function with theme functions.php file?
[英]How can I alter a plugin's function from my theme's functions.php?
下面的代码来自“ All in One SEO”包插件。 它更改了我主题的404页面标题。 我知道这就是该特定插件的工作方式,但是在这种情况下,它与我主题的404帖子标题的板载管理冲突,因此我需要重写它。
我的问题是,从我的functions.php文件中,如何在下面的代码中插入并取消is_404()代码的亮度?
class All_in_One_SEO_Pack {
function rewrite_title($header) {
global $aioseop_options;
global $wp_query;
if (!$wp_query) {
$header .= "<!-- no wp_query found! -->\n";
return $header;
}
$post = $wp_query->get_queried_object();
// the_search_query() is not suitable, it cannot just return
global $s;
global $STagging;
if (is_home() && !$this->is_static_posts_page()) {
$title = $this->internationalize($aioseop_options['aiosp_home_title']);
if (empty($title)) {
$title = $this->internationalize(get_option('blogname'));
}
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
} else if (is_attachment()) {
$title = get_the_title($post->post_parent).' '.$post->post_title.' – '.get_option('blogname');
$header = $this->replace_title($header,$title);
} else if (is_single()) {
// we're not in the loop :(
$authordata = get_userdata($post->post_author);
$categories = get_the_category();
$category = '';
if (count($categories) > 0) {
$category = $categories[0]->cat_name;
}
$title = $this->internationalize(get_post_meta($post->ID, "_aioseop_title", true));
if (!$title) {
$title = $this->internationalize(get_post_meta($post->ID, "title_tag", true));
if (!$title) {
$title = $this->internationalize(wp_title('', false));
}
}
$title_format = $aioseop_options['aiosp_post_title_format'];
/*
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%post_title%', $title, $new_title);
$new_title = str_replace('%category%', $category, $new_title);
$new_title = str_replace('%category_title%', $category, $new_title);
$new_title = str_replace('%post_author_login%', $authordata->user_login, $new_title);
$new_title = str_replace('%post_author_nicename%', $authordata->user_nicename, $new_title);
$new_title = str_replace('%post_author_firstname%', ucwords($authordata->first_name), $new_title);
$new_title = str_replace('%post_author_lastname%', ucwords($authordata->last_name), $new_title);
*/
$r_title = array('%blog_title%','%blog_description%','%post_title%','%category%','%category_title%','%post_author_login%','%post_author_nicename%','%post_author_firstname%','%post_author_lastname%');
$d_title = array($this->internationalize(get_bloginfo('name')),$this->internationalize(get_bloginfo('description')),$title, $category, $category, $authordata->user_login, $authordata->user_nicename, ucwords($authordata->first_name), ucwords($authordata->last_name));
$title = trim(str_replace($r_title, $d_title, $title_format));
$title = apply_filters('aioseop_title_single',$title);
$header = $this->replace_title($header, $title);
} else if (is_search() && isset($s) && !empty($s)) {
if (function_exists('attribute_escape')) {
$search = attribute_escape(stripcslashes($s));
} else {
$search = wp_specialchars(stripcslashes($s), true);
}
$search = $this->capitalize($search);
$title_format = $aioseop_options['aiosp_search_title_format'];
$title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
$title = str_replace('%search%', $search, $title);
$header = $this->replace_title($header, $title);
} else if (is_category() && !is_feed()) {
$category_description = $this->internationalize(category_description());
if($aioseop_options['aiosp_cap_cats']){
$category_name = ucwords($this->internationalize(single_cat_title('', false)));
}else{
$category_name = $this->internationalize(single_cat_title('', false));
}
//$category_name = ucwords($this->internationalize(single_cat_title('', false)));
$title_format = $aioseop_options['aiosp_category_title_format'];
$title = str_replace('%category_title%', $category_name, $title_format);
$title = str_replace('%category_description%', $category_description, $title);
$title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title);
$title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
} else if (is_page() || $this->is_static_posts_page()) {
// we're not in the loop :(
$authordata = get_userdata($post->post_author);
if ($this->is_static_front_page()) {
if ($this->internationalize($aioseop_options['aiosp_home_title'])) {
//home title filter
$home_title = $this->internationalize($aioseop_options['aiosp_home_title']);
$home_title = apply_filters('aioseop_home_page_title',$home_title);
$header = $this->replace_title($header, $home_title);
}
} else {
$title = $this->internationalize(get_post_meta($post->ID, "_aioseop_title", true));
if (!$title) {
$title = $this->internationalize(wp_title('', false));
}
$title_format = $aioseop_options['aiosp_page_title_format'];
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%page_title%', $title, $new_title);
$new_title = str_replace('%page_author_login%', $authordata->user_login, $new_title);
$new_title = str_replace('%page_author_nicename%', $authordata->user_nicename, $new_title);
$new_title = str_replace('%page_author_firstname%', ucwords($authordata->first_name), $new_title);
$new_title = str_replace('%page_author_lastname%', ucwords($authordata->last_name), $new_title);
$title = trim($new_title);
$title = $this->paged_title($title);
$title = apply_filters('aioseop_title_page',$title);
$header = $this->replace_title($header, $title);
}
} else if (function_exists('is_tag') && is_tag()) {
global $utw;
if ($utw) {
$tags = $utw->GetCurrentTagSet();
$tag = $tags[0]->tag;
$tag = str_replace('-', ' ', $tag);
} else {
// wordpress > 2.3
$tag = $this->internationalize(wp_title('', false));
}
if ($tag) {
$tag = $this->capitalize($tag);
$title_format = $aioseop_options['aiosp_tag_title_format'];
$title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
$title = str_replace('%tag%', $tag, $title);
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
} else if (is_404()) {
$title_format = $aioseop_options['aiosp_404_title_format'];
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%request_url%', $_SERVER['REQUEST_URI'], $new_title);
$new_title = str_replace('%request_words%', $this->request_as_words($_SERVER['REQUEST_URI']), $new_title);
$new_title = str_replace('%404_title%', $this->internationalize(wp_title('', false)), $new_title);
$header = $this->replace_title($header, $new_title);
}
return $header;
}}
我不知道模板标记是否可以在非模板文件中工作,但是如果它们可以工作,并且您不介意更改插件代码,则可以通过创建并添加自己的动作挂钩来尝试拦截插件的代码。
这与在适当位置修改插件代码几乎一样,只是自定义代码位于您自己的插件或functions.php中。
如果您不熟悉自定义操作挂钩,请参见以下文章,介绍该过程: http : //archive.extraologic.net/2007/06/wphooks/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.