Estoy intentando agregar el atributo title automaticamente a los links de wordpress me encontre con esta funcion pero me tira error en esta linea
Código:
if ($link->getAttribute('title') == '' || empty($link->getAttribute('title')))
Me tira este error
Fatal error: Can't use method return value in write context
Código PHP:
Ver originalfunction get_page_title($url){
include_once( ABSPATH . WPINC. '/class-http.php' );
$request = new WP_Http;
$result = $request->request( $url );
if( is_wp_error( $result ) )
return false;
if( preg_match("#<title>(.+)<\/title>#iU", $result, $t)) { } else {
return false;
}
}
add_filter('the_content','auto_add_title_to_link');
function auto_add_title_to_link($content){
$html = new DomDocument;
$html->loadHTML($content);
$html->preserveWhiteSpace = false;
//get all links
foreach($html->getElementsByTagName('a') as $link) {
//make sure it dosent have a title
if ($link->getAttribute('title') == '' || empty($link->getAttribute('title'))) $links[] = $link->getAttribute('href');
}
//get title and add it
foreach ($links as $link){
$title = get_page_title($link);
if (false !== $title){
$replace = $link.' title="'.$title.'"';
}
}