If you want it to display if something is "empty", you're using the wrong method with if(!empty($ptitle)){
you're telling it if it is NOT empty.
The !
is a negation character which translates as not
.
You need to use if(empty)
Plus, you also need to echo
while inside PHP.
Another thing, your $ptitle
will not echo while inside single quotes.
Use the following:
Sidenote: You may want to change if($postid == false)
to if($postid == true)
<?php
// Attributes
extract( shortcode_atts(
array(
'postid' => '',
'ptitle' => '',
), $atts )
);
$postid = $atts['postid'];
$ptitle = $atts['ptitle'];
if(empty($ptitle)){
echo "Whoops! Looks like went wrong here!";
}else{
if($postid == false) {
echo "<span class=\"ptitle\">$ptitle</span>";
} else {
echo "<span class=\"ptitle\"><a href=\"site.com/$postid\">$ptitle</a></span>";
}
}
You can also try:
<?php
// Attributes
extract( shortcode_atts(
array(
'postid' => '',
'ptitle' => '',
), $atts )
);
$postid = $atts['postid'];
$ptitle = $atts['ptitle'];
if(empty($ptitle)){
echo "Whoops! Looks like went wrong here!";
}
if(empty($postid)) {
echo "<span class=\"ptitle\">$ptitle</span>";
}
if(!empty($postid)) {
echo "<span class=\"ptitle\"><a href=\"site.com/$postid\">$ptitle</a></span>";
}