How do i insert the image title in an h1 tag for single image

Can’t get this to work:

I tried using the phplugins “function pallet_top_title” to insert the meta “title” for a photo in an <H1> tag for a single image page. I would like it to appear just above the menu. I have disabled the masthead image. This was the code I was using in custom-phplugins-pangolin.php:

function pallet_top_title() {
	// Below, the default markup for the title. The LI wrapping element is mandatory;
	// replace the inner HTML as you see fit. Retain the "masthead_pallet_top" class and styling,
	// or assign a new class, with styling defined in custom CSS.
	// Take note, the top pallet height is a 48px fixed value.
	echo '

	<li class="masthead_pallet_top">
		<h1>$photo->getMetadata(Photo::$PHOTO_TITLE)</h1>
	</li>

	';
	return false;
} 

This should do the trick:

function pallet_top_title() {
	// Below, the default markup for the title. The LI wrapping element is mandatory;
	// replace the inner HTML as you see fit. Retain the "masthead_pallet_top" class and styling,
	// or assign a new class, with styling defined in custom CSS.
	// Take note, the top pallet height is a 48px fixed value.
	echo '

	<li class="masthead_pallet_top">
		<h1>'.$photo->getMetadata(Photo::$PHOTO_TITLE).'</h1>
	</li>

	';
	return false;
} 

I think you should use the function single_top() instead:

This is what I use:

function single_top( ){
   $photo = $this->photo;
   ....
   // Title
   $my_img_title = $photo->hasMetadata(Photo::$PHOTO_TITLE) ? $photo->getMetadata(Photo::$PHOTO_TITLE) : substr($photo->getFilename(),0, 19).'...';
   $my_img_title = htmlentities($my_img_title);		
		
   echo '<h1>'. $my_img_title .'</h1>';

   ....
}
1 Like

Thanks, Daniel. This is what I used but it does not work:

function single_top( ){
	$photo = $this->photo;
	// Title
	$my_img_title = $photo->hasMetadata(Photo::$PHOTO_TITLE) ? $photo->getMetadata(Photo::$PHOTO_TITLE) : substr($photo->getFilename(),0, 19).'...';
	$my_img_title = htmlentities($my_img_title);		
	echo '<h1>'. $my_img_title .'</h1>';
}

Check your messages.

1 Like

For everyone else following this, my example code finished with ... indicating that there’s more to put there. One thing is return true; in order to preserve the default single page image display!

1 Like