I want to add a video icon / gallery icon next to title, which post contain video / photo gallery. Im on latest wordpress and making my own custom theme. Currently im using
<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
for title. I was worked on another theme (not mine) before which have video icon on titles. The code i found in functions.php
<?php
function title_embed($title,$conts)
{
$pattern ="/<object> ?.* </object>/isx";
$return =preg_match($pattern, $conts,$result);
if($result)
{
$return = $title.'<span class="video-icon"></span>';
return $return;
}
else{return $title;}
}
which makes a span class on titles on posts contains <object>
and </object>
. The title code was
<a href="<?php echo $arraybox['link'][0];?>" title="<?php echo $arraybox['alt'][0];?>"><h2><?php echo $arraybox['title'][0];?></h2></a>
I’ve tried pasting the above code to my current theme’s functions.php but nothing happened. I think the problem may be the way I’m calling title. I’ve googled for a resource and wasted my 6-7 hours.
basically, your code looks for
<object> </object>
tags in the content andif found it appends the span whose class is video-icon to the title. This span will probably be styled as a video icon in css.
Have you tried calling your function with
$conts= the_content()