WordPress / WordPress/WordPress-Coding-Standards

Recommend the_title_attribute() instead of esc_attr( get_the_title() )

Open
#1,778 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Is your feature request related to a problem?

the_title_attribute() automatically strips tags from get_the_title() and escapes the echoed or returned value ready for it to be added to an attribute.

We should recommend (WordPress-Extra) that the_title_attribute() be used instead of esc_attr( get_the_title() ), perhaps with a slightly different message for when that is proceeded by an echo or <?php=.

<img src="..." alt="<?php echo esc_attr( get_the_title() ) ?>">

=>

<img src="..." alt="<?php the_title_attribute(); ?>">

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the WordPress-Extra check that handles esc_attr( get_the_title() ) and inspect how it reports equivalent patterns. Done means recommending the_title_attribute(), with a distinct message where echo or <?php= is involved, and covering the supplied HTML example.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
39/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.