# auto-alt-text/2.5.2/src/App/AltTextGeneratorParentPostTitle.php

Auto Alt Text, version 2.5.2. 33 lines.

- Page: https://pluginprobe.com/plugins/auto-alt-text/2.5.2/code/src/App/AltTextGeneratorParentPostTitle.php
- Raw: https://pluginprobe.com/plugins/auto-alt-text/2.5.2/raw/src/App/AltTextGeneratorParentPostTitle.php
- Modified: 2024-03-10T14:55:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/auto-alt-text/2.5.2/code/src/App/AltTextGeneratorParentPostTitle.php#L10-L20`.

```php
<?php
namespace AATXT\App;

class AltTextGeneratorParentPostTitle implements AltTextGeneratorInterface
{
    private function __construct()
    {
    }

    /**
     * @return AltTextGeneratorParentPostTitle
     */
    public static function make(): AltTextGeneratorParentPostTitle
    {
        return new self();
    }

    /**
     * Get the alt text of the image
     * @param int $imageId
     * @return string
     */
    public function altText(int $imageId): string
    {
        $parentPost = get_post_parent($imageId);

        if (empty($parentPost)) {
            return '';
        }

        return get_the_title($parentPost);
    }
}
```
