[theme-reviewers] No-Title Filter for the_title()

Justin Tadlock justin at justintadlock.com
Wed Mar 9 22:40:53 UTC 2011


Mine just outputs "untitled" now.  However, I've added a "no-title" CSS 
class where users can use display: none if they don't want that to appear.

There are definitely several different approaches though.

On 3/8/2011 3:32 PM, Emil Uzelac wrote:
> I like the filter, good approach, also simple use for this would be:
>
> <h1 class="entry-title">
> <?php
>     if ( ! get_the_title() ) {
>         print '<a href="' . esc_url( get_permalink() ) . '">Untitled</a>';
>     ?>
> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 
> 'Permalink to %s', 'fit' ), the_title_attribute( 'echo=0' ) ); ?>" 
> rel="bookmark"><?php the_title(); ?></a>
> </h1>
>
> Michael/Chip combination.
>
> If there is no title the Untitled will need to be in place where h1 
> should be instead of having h1 empty in source code and place a link 
> on top somewhere. i.e. "Empty Text Node" is there but not visible to 
> let's say Search Engines or any site that would crawl this.
>
> Emil
>
> *Emil Uzelac* | ThemeID | T: 224-444-0006 | Twitter: @EmilUzelac | E: 
> emil at themeid.com <mailto:emil at themeid.com> | http://themeid.com 
> <http://themeid.com/>
> Make everything as simple as possible, but not simpler. - Albert Einstein
>
>
>
> On Tue, Mar 8, 2011 at 2:56 PM, Edward Caissie 
> <edward.caissie at gmail.com <mailto:edward.caissie at gmail.com>> wrote:
>
>     Perhaps I wasn't clear with my earlier reply ...
>
>     I agree with Mike on the title should be empty if the author
>     chooses not to write one; although I also would not recommend this
>     particular item fall under the Theme Review guidelines. The
>     end-users will make it clear if they think the Theme author's
>     design concept fits their needs ... or not.
>
>     I'm still not thrilled with the method I am using in my themes but
>     this has given me a few more ideas to play with.
>
>
>     On Tue, Mar 8, 2011 at 3:45 PM, Chip Bennett <chip at chipbennett.net
>     <mailto:chip at chipbennett.net>> wrote:
>
>         I would use:
>
>             if ( ! get_the_title() )
>
>
>         Rather than:
>
>             $title = the_title( '', '', false );
>             if ( empty( $title ) )
>
>
>         But, that doesn't really address your underlying point, which
>         I believe is valid, but outside the scope of the Theme Review
>         guidelines. I think we've got a good balance, by requiring a
>         permalink to the Single-Post view, but not dictating *how*
>         that permalink appears. Our concern is the UX; the design
>         consideration can remain a matter between the developer and
>         the end users. I'd prefer we, as Theme reviewers, not get in
>         the middle of that.
>
>         Chip
>
>
>         On Tue, Mar 8, 2011 at 2:39 PM, <michael at mfields.org
>         <mailto:michael at mfields.org>> wrote:
>
>             Right on, I can totally see that need. The main thing the
>             erks me about
>             solutions such as this is that they take the authors
>             intentions and throw
>             them out the window. If I am writing a post and I choose
>             to leave the
>             title blank, I would expect the title to be blank. I do
>             not want the title
>             replaced with "no title". To me it has the effect of a
>             designer leaving in
>             FPO images in a finished design ... IMO it looks sloppy.
>
>             If a permalink is needed, I would suggest that it be added
>             somewhere else
>             in the template in a conditional check. the_title can
>             still be used for
>             this:
>
>             $title = the_title( '', '', false );
>             if ( empty( $title ) ) {
>                print '<a href="' . esc_url( get_permalink() ) .
>             '">Permalink</a>';
>             }
>
>             -Mike
>
>
>             > The issue arises when Post Title is the only available
>             permalink to the
>             > Single-Post view. In this case, the developer may want
>             to provide text
>             > such
>             > as "No Title", etc., so that the permalink still gets
>             displayed.
>             >
>             > Chip
>             >
>             > On Tue, Mar 8, 2011 at 2:15 PM, <michael at mfields.org
>             <mailto:michael at mfields.org>> wrote:
>             >
>             >> Is there a need for a conditional test?
>             >>
>             >> I wrap all my code within the function and the
>             conditional as pect is
>             >> handled for you:
>             >>
>             >> the_title( '<h2>', '</h2>' );
>             >>
>             >> This way the tags will not be printed if the title is
>             empty.
>             >>
>             >> -Mike
>             >>
>             >> > Ran across this suggestion on the WPORG support forums:
>             >> >
>             >> >
>             >>
>             http://wordpress.org/support/topic/handling-display-of-title-when-none-exists?replies=1
>             >> >
>             >> > I like this approach; it is cleaner than performing a
>             conditional test
>             >> in
>             >> > the template file.
>             >> >
>             >> > Just thought I'd pass it along...
>             >> >
>             >> > Chip
>             >> > _______________________________________________
>             >> > theme-reviewers mailing list
>             >> > theme-reviewers at lists.wordpress.org
>             <mailto:theme-reviewers at lists.wordpress.org>
>             >> >
>             http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>             >> >
>             >>
>             >>
>             >> _______________________________________________
>             >> theme-reviewers mailing list
>             >> theme-reviewers at lists.wordpress.org
>             <mailto:theme-reviewers at lists.wordpress.org>
>             >> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>             >>
>             > _______________________________________________
>             > theme-reviewers mailing list
>             > theme-reviewers at lists.wordpress.org
>             <mailto:theme-reviewers at lists.wordpress.org>
>             > http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>             >
>
>
>             _______________________________________________
>             theme-reviewers mailing list
>             theme-reviewers at lists.wordpress.org
>             <mailto:theme-reviewers at lists.wordpress.org>
>             http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
>
>         _______________________________________________
>         theme-reviewers mailing list
>         theme-reviewers at lists.wordpress.org
>         <mailto:theme-reviewers at lists.wordpress.org>
>         http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
>
>     _______________________________________________
>     theme-reviewers mailing list
>     theme-reviewers at lists.wordpress.org
>     <mailto:theme-reviewers at lists.wordpress.org>
>     http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110309/e3f67ce9/attachment-0001.htm>


More information about the theme-reviewers mailing list