本文整理汇总了PHP中wpseo_replace_vars函数的典型用法代码示例。如果您正苦于以下问题:PHP wpseo_replace_vars函数的具体用法?PHP wpseo_replace_vars怎么用?PHP wpseo_replace_vars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpseo_replace_vars函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_title_separator
public function get_title_separator($separator)
{
if (class_exists('WPSEO_Option_Titles')) {
$separator = wpseo_replace_vars('%%sep%%', array());
}
return $separator;
}
示例2: item_to_response
/**
* Convert the given term into a analyzable object.
*
* @param mixed $item The term for which to build the analyzer data.
*
* @return array
*/
protected function item_to_response($item)
{
$focus_keyword = $this->get_focus_keyword($item);
$title = str_replace(' %%page%% ', ' ', $this->get_title($item));
$meta = $this->get_meta_description($item);
$description = $item->description;
/**
* Filter the term description for recalculation.
*
* @param string $description Content of the term. Modify to reflect front-end content.
* @oaram WP_Term $item The term the description comes from.
*/
$description = apply_filters('wpseo_term_description_for_recalculation', $description, $item);
return array('term_id' => $item->term_id, 'taxonomy' => $item->taxonomy, 'text' => $description, 'keyword' => $focus_keyword, 'url' => urldecode($item->slug), 'pageTitle' => apply_filters('wpseo_title', wpseo_replace_vars($title, $item, array('page'))), 'meta' => apply_filters('wpseo_metadesc', wpseo_replace_vars($meta, $item)), 'keyword_usage' => array($focus_keyword => WPSEO_Taxonomy_Meta::get_keyword_usage($focus_keyword, $item->term_id, $item->taxonomy)));
}
示例3: item_to_response
/**
* Map the posts to a response array
*
* @param WP_Post $item The post for which to build the analyzer data.
*
* @return array
*/
protected function item_to_response($item)
{
$focus_keyword = WPSEO_Meta::get_value('focuskw', $item->ID);
$content = $item->post_content;
/**
* Filter the post content for use in the SEO score recalculation.
*
* @param string $content Content of the post. Modify to reflect front-end content.
* @param WP_Post $item The Post object the content comes from.
*/
$content = apply_filters('wpseo_post_content_for_recalculation', $content, $item);
// Apply shortcodes.
$content = do_shortcode($content);
return array('post_id' => $item->ID, 'text' => $content, 'keyword' => $focus_keyword, 'url' => urldecode($item->post_name), 'pageTitle' => apply_filters('wpseo_title', wpseo_replace_vars($this->get_title($item->ID, $item->post_type), $item)), 'meta' => apply_filters('wpseo_metadesc', wpseo_replace_vars($this->get_meta_description($item->ID, $item->post_type), $item)), 'keyword_usage' => array($focus_keyword => WPSEO_Meta::keyword_usage($focus_keyword, $item->ID)));
}
示例4: google_plus_title
/**
* Output the Google+ specific title
*/
public function google_plus_title()
{
if (is_singular()) {
$title = WPSEO_Meta::get_value('google-plus-title');
/**
* Filter: 'wpseo_googleplus_title' - Allow developers to change the Google+ specific title
*
* @api string $title The title string
*/
$title = trim(apply_filters('wpseo_googleplus_title', $title));
if (is_string($title) && $title !== '') {
$title = wpseo_replace_vars($title, get_post());
echo '<meta itemprop="name" content="', esc_attr($title), '">', "\n";
}
}
}
示例5: test_wpseo_replace_vars
/**
* @covers wpseo_replace_vars
*/
public function test_wpseo_replace_vars()
{
// create author
$user_id = $this->factory->user->create(array('user_login' => 'User_Login', 'display_name' => 'User_Nicename'));
// create post
$post_id = $this->factory->post->create(array('post_title' => 'Post_Title', 'post_content' => 'Post_Content', 'post_excerpt' => 'Post_Excerpt', 'post_author' => $user_id, 'post_date' => date('Y-m-d H:i:s', strtotime('2000-01-01 2:30:00'))));
// get post
$post = get_post($post_id);
$input = '%%title%% %%excerpt%% %%date%% %%name%%';
$expected = 'Post_Title Post_Excerpt ' . mysql2date(get_option('date_format'), $post->post_date, true) . ' User_Nicename';
$output = wpseo_replace_vars($input, (array) $post);
$this->assertEquals($expected, $output);
/*
TODO
- Test all Basic Variables
- Test all Advanced Variables
*/
}
示例6: get_replace_vars
/**
* Prepares the replace vars for localization.
*
* @return array replace vars
*/
private function get_replace_vars()
{
$post = $this->get_metabox_post();
$cached_replacement_vars = array();
$vars_to_cache = array('date', 'id', 'sitename', 'sitedesc', 'sep', 'page', 'currenttime', 'currentdate', 'currentday', 'currentmonth', 'currentyear');
foreach ($vars_to_cache as $var) {
$cached_replacement_vars[$var] = wpseo_replace_vars('%%' . $var . '%%', $post);
}
return $cached_replacement_vars;
}
示例7: metadesc
/**
* Outputs the meta description element or returns the description text.
*
* @param bool $echo Whether or not to echo the description.
* @return string
*/
function metadesc($echo = true)
{
if (get_query_var('paged') && get_query_var('paged') > 1) {
return;
}
global $post, $wp_query;
$options = get_wpseo_options();
$metadesc = '';
if (is_singular()) {
$metadesc = wpseo_get_value('metadesc');
if ($metadesc == '' || !$metadesc) {
if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] != '') {
$metadesc = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
}
}
} else {
if (is_search()) {
$metadesc = '';
} else {
if ($this->is_home_posts_page() && isset($options['metadesc-home'])) {
$metadesc = wpseo_replace_vars($options['metadesc-home'], array());
} else {
if ($this->is_posts_page()) {
$metadesc = wpseo_get_value('metadesc', get_option('page_for_posts'));
if (($metadesc == '' || !$metadesc) && isset($options['metadesc-' . $post->post_type])) {
$page = get_post(get_option('page_for_posts'));
$metadesc = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $page);
}
} else {
if ($this->is_home_static_page()) {
global $post;
$metadesc = wpseo_get_value('metadesc');
if (($metadesc == '' || !$metadesc) && isset($options['metadesc-' . $post->post_type])) {
$metadesc = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
}
} else {
if (is_category() || is_tag() || is_tax()) {
$term = $wp_query->get_queried_object();
$metadesc = wpseo_get_term_meta($term, $term->taxonomy, 'desc');
if (!$metadesc && isset($options['metadesc-' . $term->taxonomy])) {
$metadesc = wpseo_replace_vars($options['metadesc-' . $term->taxonomy], (array) $term);
}
} else {
if (is_author()) {
$author_id = get_query_var('author');
$metadesc = get_the_author_meta('wpseo_metadesc', $author_id);
if (!$metadesc && isset($options['metadesc-author'])) {
$metadesc = wpseo_replace_vars($options['metadesc-author'], (array) $wp_query->get_queried_object());
}
} else {
if (function_exists('is_post_type_archive') && is_post_type_archive()) {
$post_type = get_post_type();
if (isset($options['metadesc-ptarchive-' . $post_type]) && '' != $options['metadesc-ptarchive-' . $post_type]) {
$metadesc = $options['metadesc-ptarchive-' . $post_type];
}
}
}
}
}
}
}
}
}
$metadesc = apply_filters('wpseo_metadesc', trim($metadesc));
if ($echo) {
if (!empty($metadesc)) {
echo '<meta name="description" content="' . esc_attr(strip_tags(stripslashes($metadesc))) . '"/>' . "\n";
} else {
if (current_user_can('manage_options') && is_singular()) {
echo '<!-- ' . __('Admin only notice: this page doesn\'t show a meta description because it doesn\'t have one, either write it for this page specifically or go into the SEO -> Titles menu and set up a template.', 'wordpress-seo') . ' -->' . "\n";
}
}
} else {
return $metadesc;
}
}
示例8: description
/**
* Output the OpenGraph description, specific OG description first, if not, grab the meta description.
*
* @param bool $echo Whether to echo or return the description
*
* @return string $ogdesc
*/
public function description($echo = true)
{
$ogdesc = '';
if (is_front_page()) {
$ogdesc = $this->options['og_frontpage_desc'] !== '' ? $this->options['og_frontpage_desc'] : $this->metadesc(false);
}
if (is_singular()) {
$ogdesc = WPSEO_Meta::get_value('opengraph-description');
// Replace WP SEO Variables
$ogdesc = wpseo_replace_vars($ogdesc, get_post());
// Use metadesc if $ogdesc is empty
if ($ogdesc === '') {
$ogdesc = $this->metadesc(false);
}
// og:description is still blank so grab it from get_the_excerpt()
if (!is_string($ogdesc) || is_string($ogdesc) && $ogdesc === '') {
$ogdesc = str_replace('[…]', '…', strip_tags(get_the_excerpt()));
}
}
if (is_category() || is_tag() || is_tax()) {
$ogdesc = trim(strip_tags(term_description()));
}
// Strip shortcodes if any
$ogdesc = strip_shortcodes($ogdesc);
/**
* Filter: 'wpseo_opengraph_desc' - Allow changing the OpenGraph description
*
* @api string $ogdesc The description string.
*/
$ogdesc = apply_filters('wpseo_opengraph_desc', $ogdesc);
if (is_string($ogdesc) && $ogdesc !== '') {
if ($echo !== false) {
$this->og_tag('og:description', $ogdesc);
}
}
return $ogdesc;
}
示例9: generate_metadesc
/**
* Generates the meta description text.
*/
private function generate_metadesc()
{
global $post, $wp_query;
$metadesc = '';
$metadesc_override = false;
$post_type = '';
$template = '';
if (is_object($post) && (isset($post->post_type) && $post->post_type !== '')) {
$post_type = $post->post_type;
}
if (is_singular()) {
if ($metadesc === '' && $post_type !== '' && isset($this->options['metadesc-' . $post_type])) {
$template = $this->options['metadesc-' . $post_type];
$term = $post;
}
$metadesc_override = WPSEO_Meta::get_value('metadesc');
} else {
if (is_search()) {
$metadesc = '';
} elseif ($this->is_home_posts_page()) {
$template = $this->options['metadesc-home-wpseo'];
$term = array();
if (empty($template)) {
$template = get_bloginfo('description');
}
} elseif ($this->is_posts_page()) {
$metadesc = WPSEO_Meta::get_value('metadesc', get_option('page_for_posts'));
if ($metadesc === '' && $post_type !== '' && isset($this->options['metadesc-' . $post_type])) {
$page = get_post(get_option('page_for_posts'));
$template = $this->options['metadesc-' . $post_type];
$term = $page;
}
} elseif ($this->is_home_static_page()) {
$metadesc = WPSEO_Meta::get_value('metadesc');
if ($metadesc === '' && $post_type !== '' && isset($this->options['metadesc-' . $post_type])) {
$template = $this->options['metadesc-' . $post_type];
}
} elseif (is_category() || is_tag() || is_tax()) {
$term = $wp_query->get_queried_object();
$metadesc_override = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'desc');
if (is_object($term) && isset($term->taxonomy, $this->options['metadesc-tax-' . $term->taxonomy])) {
$template = $this->options['metadesc-tax-' . $term->taxonomy];
}
} elseif (is_author()) {
$author_id = get_query_var('author');
$metadesc = get_the_author_meta('wpseo_metadesc', $author_id);
if ((!is_string($metadesc) || $metadesc === '') && '' !== $this->options['metadesc-author-wpseo']) {
$template = $this->options['metadesc-author-wpseo'];
}
} elseif (is_post_type_archive()) {
$post_type = get_query_var('post_type');
if (is_array($post_type)) {
$post_type = reset($post_type);
}
if (isset($this->options['metadesc-ptarchive-' . $post_type])) {
$template = $this->options['metadesc-ptarchive-' . $post_type];
}
} elseif (is_archive()) {
$template = $this->options['metadesc-archive-wpseo'];
}
// If we're on a paginated page, and the template doesn't change for paginated pages, bail.
if ((!is_string($metadesc) || $metadesc === '') && get_query_var('paged') && get_query_var('paged') > 1 && $template !== '') {
if (strpos($template, '%%page') === false) {
$metadesc = '';
}
}
}
$post_data = $post;
if (is_string($metadesc_override) && '' !== $metadesc_override) {
$metadesc = $metadesc_override;
if (isset($term)) {
$post_data = $term;
}
} else {
if ((!is_string($metadesc) || '' === $metadesc) && '' !== $template) {
if (!isset($term)) {
$term = $wp_query->get_queried_object();
}
$metadesc = $template;
$post_data = $term;
}
}
$metadesc = wpseo_replace_vars($metadesc, $post_data);
/**
* Filter: 'wpseo_metadesc' - Allow changing the WP SEO meta description sentence.
*
* @api string $metadesc The description sentence.
*/
$this->metadesc = apply_filters('wpseo_metadesc', trim($metadesc));
}
示例10: wpseo_ajax_replace_vars
/**
* Used in the editor to replace vars for the snippet preview
*/
function wpseo_ajax_replace_vars()
{
check_ajax_referer('wpseo-replace-vars');
$post = get_post($_POST['post_id']);
$omit = array('excerpt', 'excerpt_only', 'title');
echo wpseo_replace_vars(stripslashes($_POST['string']), $post, $omit);
die;
}
示例11: get_single_sitemap_line
/**
* Get a single sitemap line to output in the xml sitemap
*
* @param $val
* @param $key
* @param $xtra
*
* @return null|string
*/
private function get_single_sitemap_line($val, $key, $xtra)
{
$val = $this->clean_string($val);
if (in_array($key, array('description', 'category', 'tag', 'title'))) {
$val = ent2ncr(esc_html($val));
}
if (!empty($val)) {
return "\t\t\t<video:" . $key . $xtra . '>' . wpseo_replace_vars($val, array()) . '</video:' . $key . ">\n";
}
return null;
}
示例12: _meta_keywords
public function _meta_keywords()
{
$wpseo_front = null;
if (isset($GLOBALS['wpseo_front'])) {
$wpseo_front = $GLOBALS['wpseo_front'];
} elseif (class_exists('WPSEO_Frontend') && method_exists('WPSEO_Frontend', 'get_instance')) {
$wpseo_front = WPSEO_Frontend::get_instance();
}
$current_action = $this->controller->get_current_action();
switch ($current_action) {
case 'showlisting':
global $post;
$listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
$prev_post = $post;
$post = get_post($listing_id);
if (is_object($wpseo_front)) {
$wpseo_front->metadesc();
$wpseo_front->metakeywords();
}
$post = $prev_post;
break;
case 'browsecategory':
case 'browsetag':
if ($current_action == 'browsetag') {
$term = get_term_by('slug', get_query_var('tag'), WPBDP_TAGS_TAX);
} else {
$term = get_term_by('slug', get_query_var('category'), WPBDP_CATEGORY_TAX);
if (!$term && get_query_var('category_id')) {
$term = get_term_by('id', get_query_var('category_id'), WPBDP_CATEGORY_TAX);
}
}
if ($term) {
$metadesc = method_exists('WPSEO_Taxonomy_Meta', 'get_term_meta') ? WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'desc') : wpseo_get_term_meta($term, $term->taxonomy, 'desc');
if (!$metadesc && is_object($wpseo_front) && isset($wpseo_front->options['metadesc-tax-' . $term->taxonomy])) {
$metadesc = wpseo_replace_vars($wpseo_front->options['metadesc-tax-' . $term->taxonomy], (array) $term);
}
if ($metadesc) {
echo '<meta name="description" content="' . esc_attr(strip_tags(stripslashes($metadesc))) . '"/>' . "\n";
}
}
break;
case 'main':
if (is_object($wpseo_front)) {
$wpseo_front->metadesc();
$wpseo_front->metakeywords();
}
break;
default:
break;
}
}
示例13: page_title
/**
* Retrieve the page title.
*
* @param int $post_id Post to retrieve the title for.
*
* @return string
*/
private function page_title($post_id)
{
$fixed_title = WPSEO_Meta::get_value('title', $post_id);
if ($fixed_title !== '') {
return $fixed_title;
}
$post = get_post($post_id);
$options = WPSEO_Options::get_option('wpseo_titles');
if (is_object($post) && (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '')) {
$title_template = $options['title-' . $post->post_type];
$title_template = str_replace(' %%page%% ', ' ', $title_template);
return wpseo_replace_vars($title_template, $post);
}
return wpseo_replace_vars('%%title%%', $post);
}
示例14: ctfw_event_calendar_head_title
function ctfw_event_calendar_head_title($title, $sep, $seplocation)
{
global $post;
$new_title = $title;
// Theme supports this?
$support = get_theme_support('ctfw-event-calendar-head-title');
if (!empty($support)) {
// Arguments from theme support or default
$args = isset($support[0]) ? $support[0] : array();
$args = wp_parse_args($args, array('page_template' => 'events-calendar.php'));
// Only on event calendar page template
if (is_page_template(CTFW_THEME_PAGE_TPL_DIR . '/' . $args['page_template'])) {
$parts = array();
// Get month
if (!empty($_GET['month'])) {
/* translators: this is the PHP date format used for <title> on event calendar months */
$parts[] = date_i18n(_x('F Y', 'event calendar', 'church-theme-framework'), strtotime($_GET['month']));
}
// Get category
if (!empty($_GET['category'])) {
// Get term from slug
$category = get_term_by('slug', $_GET['category'], 'ctc_event_category');
// Get name
if (!empty($category->name)) {
$parts[] = wptexturize($category->name);
}
}
// Combine parts
if ($parts) {
// Is Yoast SEO plugin active?
$wpseo_separator = '';
if (function_exists('wpseo_replace_vars')) {
$wpseo_separator = trim(wpseo_replace_vars('%%sep%%', array()));
if (!empty($wpseo_separator)) {
$wpseo_separator = ' ' . $wpseo_separator . ' ';
}
}
// Get separator
if ($wpseo_separator) {
// use Yoast SEO plugin's separator if available
$separator = $wpseo_separator;
} else {
// otherwise fall back to ' | ' WordPress default
/* translators: separator for <title> content */
$separator = _x(' | ', 'head title', 'church-theme-framework');
}
// Combine month and category into suffix
$month_category = $separator . implode($separator, $parts);
// separator at left
$month_category_right = implode($separator, $parts) . $separator;
// separator at right
// Post title was found in <title>
// Insert month and category after that (e.g. Monthly Calendar - Month - Category - Site Title)
$post_title = isset($post->post_title) ? wptexturize($post->post_title) : '';
$post_title_esc = preg_quote($post_title);
if (!empty($post_title) && preg_match('/' . $post_title_esc . preg_quote($separator) . '/', $title)) {
$new_title = preg_replace('/(' . $post_title_esc . ')/', '$1' . $month_category, $title);
} else {
$site_title = get_bloginfo('name', 'display');
// wptexturize applied
$site_title_esc = preg_quote($site_title);
if (!empty($site_title)) {
// Is site title found at end of title?
// Insert month and category before that (e.g. Custom Title - Month - Category - Site Name)
if (preg_match('/' . $site_title_esc . '$/', $title)) {
$new_title = preg_replace('/(' . $site_title_esc . ')$/', $month_category_right . '$1', $title);
} else {
$new_title .= $month_category;
}
}
}
}
}
}
return $new_title;
}
示例15: test_get_title_from_options
/**
* @covers WPSEO_Frontend::get_title_from_options
*/
public function test_get_title_from_options()
{
// should return an empty string
$this->assertEmpty(self::$class_instance->get_title_from_options('__not-existing-index'));
// create and go to post
$post_id = $this->factory->post->create();
$this->go_to(get_permalink($post_id));
$var_source = (array) get_queried_object();
$expected_title = wpseo_replace_vars('%%title%% %%sep%% %%sitename%%', $var_source);
$this->assertEquals($expected_title, self::$class_instance->get_title_from_options('__not-existing-index', $var_source));
// test with an option that exists
$index = 'title-post';
$expected_title = wpseo_replace_vars(self::$class_instance->options[$index], $var_source);
$this->assertEquals($expected_title, self::$class_instance->get_title_from_options($index, $var_source));
}