Hola amigo tengo un problemita que me di cuenta hace rato.
Tengo un shortcode para obtener el nombre de una pagina desde la url, lo que pasa es que si la url sale es asi forosdelweb.rt.com/titulo-del-post no me sale el titulo solo la url.
Aqui les dejo el codigo para obtener el titulo (Lo arme aqui mismo en foros del web).
Código PHP:
add_shortcode( 'fuente', 'fuente_check_shortcode' );
function fuente_check_shortcode( $atts, $content = null ) {
if(preg_match('/href/i',$content,$matches2)){
preg_match('/<a[^>]*href="([^"].*)"[^>]*>.*<\/a>/i',$content,$matches);
$url = $matches[1];
function getTitle($url){
$str = file_get_contents($url);
if(strlen($str)>0){
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title);
return $title[1];
}
}
$ti = getTitle($url);
}elseif(preg_match('/^[http|https]/i',$content,$matches2)){
$url = $content;
function getTitle($content){
$str = file_get_contents($content);
if(strlen($str)>0){
preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title);
return $title[1];
}
}
$ti = getTitle($content);
}
return '
<style>
#fuente{
float:left;
width:100%;
text-align:left;
padding: 10px 0 10px 0;
margin: 0 0 0 -10px;
color: #000;
text-decoration: none;
z-index:100;
font-family: "Lato", Helvetica, Arial, sans-serif;
}
#info{
float:left;
margin-left:10px;
color: #000;
text-decoration: none;
font-family: "Lato", Helvetica, Arial, sans-serif;
font-weight: 500;
font-size:18px;
}
</style>
<div id="fuente">
<span id="info">Fuente de información:</span><span style="float:left; padding: 5px 0 0 7px;"><hr style="width:475px;position:absolute;color:#E6E6E6"></span>
<br>
<br>
<br>
<span style="float:left;padding:0 10px 0;"><img src="http://g.etfv.co/'.$url.'" width="16" height="16"></span>
<span style="float:left;width:600px;"><a href="'.$url.'" title="'.$ti.'" target="_blank"><b>'.$ti.'</b></a></span>
</div>
';
}