I just install Wordpress SEO plugin by Yoast, test the title re-write function and it works in my title bar (single post). However when I try to call the title in widget, I just get error message
Warning: Missing argument 1 for kpndg()...
I insert this code in theme functions.php
add_filter( 'wpseo_title', 'kpndg' );
function kpndg( $title ) {
return $title;
}
Then call it in my widget:
$out.='<div class="trending-bar add-active bar-' . $i . '">';
$out.='<a class="trending-link" href="'.get_permalink().'"> </a>';
$out.='<div class="title">'.kpndg().'</div>';
$out.='<div class="trending-color-wrapper">';
$out.='<div class="trending-color-layer"></div>';
$out.='<div class="trending-color"></div>';
$out.='<div class="trending-meta">' . $meta . '</div>';
$out.='</div>';
$out.='</div>';
I can't figure out what is the problem in that code.
FYI: I use Engine theme by Industrial Themes
This line: $out.='<div class="title">'.kpndg().'</div>';
You need to specify an argument... Or, alternatively, set a default value for the $title
argument:
add_filter( 'wpseo_title', 'kpndg' );
function kpndg( $title = 'foo' ) {
return $title;
}
Edit
Are you sure you didn't mean to use get_post_meta(get_the_ID(), '_yoast_wpseo_title', true);
in place of kpndg()
?
Edit #2
Instead of adding a new filter for wpseo_title
, just create a "helper function":
function kpndg() {
return get_post_meta(get_the_ID(), '_yoast_wpseo_title', true) ?: get_the_title();
}
Then, within the loop, you can call echo kpndg()