ClassicPress PetitionsClassicPress Petitions
This is a read-only archive. Post or comment on the live version of this page on our forums.

Hide Title

January 2, 2019 · 15:04 · hyperclock
Description

There are plugins that handle this nicely, but I would prefer this to be a standard core product. And it shouldn't be difficult to implement.

Voters
+1 more
Tags
Request: Add feature
Discussion
Pieter Bos

It could be an idea to link to plugins that handle this, if only as a point of reference.

Raymund

I used hide title plugin in the past before switching to generatepress theme which had this functionality. Hiding the title and showing only the content should be in core. But if not included in core, maybe it can be included in an open source script repository where I can copy paste, instead of using third party plugin.

Tim Kaye

I have just taken a look through the WP repo, and it seems to me that by far the best plugin for this job is Title Remover, which can be found at https://wordpress.org/plugins/title-remover/

The others just hide the title with CSS and javascript, whereas that one actually removes the title from the generated HTML.

Greg Schoppe

The reason that there isn't a hide the title feature in core is that the title isn't a pre-defined block of HTML, like featured images are. it's a call to get raw text that the theme wraps in tags and styling. As such, we can't just blank the_title(), as it will produce empty tags, and will hide the title in other places where it should exist.

I do not believe this should be done without introducing new functions to the theme, as the existing solutions are all very hacky, in how they interact with arbitrary themes.

One solution would be to add a setting to the admin panel that just controls a function called has_title(), but I think we can do better than that.

A related problem that is frequently seen with titles, is the lack of proper header tags. On archive pages and on the home page, the title should usually be an H2, whereas on single pages, it should be an H1, if it is the primary post on the page. Perhaps we could add a function for the_headline() that outputs the title with the appropriate tag (of course allowing the theme to override the tag where they wish). This could be combined with another new function the_masthead() that would output the site name/logo of the site in a standardized way that accounts for all the various header tag needs (on single pages, the site name should be in a span... on the homepage it should be the H1).

These functions could be used to both enable themes to support hiding the title out of box, and also to try to bring better standards into how themes semantically handle headers.

Tim Kaye

Sounds good to me, @Greg Schoppe!

Wells

If history is any guide, adding new functions won't help standardize how theme developers handle anything - more likely the opposite. The "various header tag needs" are too numerous to account for, and I really don't like the thought of having to add yet another override for something as simple as changing how a title is printed. Especially when, as you say, there are already plugins that handle this nicely.

James Nylen

I think this is enough of an edge case that it should be built into the theme. If you want to hide post titles on your site, then make a (child) theme that doesn't display titles.

I'm curious about the use cases for hiding the post title, though. Generally a page should have a single, definitive title, which in WP/CP context is the post_title.

In what situation(s) is it useful to hide the title instead?

Greg Schoppe

@james the situation is primarily seen by users of Page Builders, who may need to create landing page layouts that display the title in unique ways (overlay on an image for example), or even hide it entirely (common on frontpages). However, since there isn't a standardized way of saying "I don't want a title on this page", the theme and page builder need to be designed to work together to accomplish this, which is a little weak.

@wells, unfortunately, there really aren't any plugins that handle this well. even the best of them is just hiding the title element with css, rather than actually removing it.

even just a checkbox that you declare theme support for would be an improvement, because it would standardize the option across themes. you could leave all the rendering up to the discretion of the theme author.

Tim Kaye

@Greg, I think this one manages to actually remove the title and doesn't just hide it with CSS: https://wordpress.org/plugins/title-remover/

Greg Schoppe

@Tim, that one has two serious issues.

First, it causes the title to output as an empty string, but doesn't prevent the wrapping tags from outputting, so even in the best case scenario, your page has an empty H1 messing with SEO and accessibility.

Second, it removes the title from any other posts that appear inside a loop on the page, so if you use a secondary loop to display related posts, and any of them are set to hide their on their singular page, their titles will go missing on that page too.

In the WP/CP codebase, there isn't a way to say "this is the primary title", so there is no good way to remove that title selectively, and there is no delineation around wrapping elements of the title, so those can't be properly removed.

Fabian Wolf

Actually, there is. The "primary title" is the post_title. Yes, you may add semantic HTML to the post_content, thus add an initial h1 tag, but nonetheless, the primary title is and always was 'post_title'.

Greg Schoppe

post_title of which post? A post's template may contain other posts in it, such as related posts, or a recent posts widget in the sidebar.

post_title would only want to be suppressed for the primary instance of post_title on the page, not any of those potential other instances. And there is no way to tell the difference.

Try it for yourself.

  1. Create a test site running twenty fourteen (or any theme with a sidebar on the single post template)
  2. Install Title Remover
  3. In the sidebar, add a recent posts widget.
  4. Add a post, and set it to hide the title.
  5. View any other post.
  6. Check out the recent posts widget. The title of the post you created is missing.
Fabian Wolf

The base WP_Query? global $wp_query, or hook into the first available hook which already contains the post ID (I've done that to create my shortcode assets on-demand loader).

All instances of get_the_title? Hence the fuck-up?

Greg Schoppe

But even identifying the correct ID isn't enough.

Let's go back to the same example site I hypothetically created in my last reply. Now let's look at the post that we created and hid the title for. That post's title appears twice on it's page. Once as the main title, and once in the sidebar, under recent posts.

If you set the title as hidden in the back end, it will be hidden for both, but it should only be hidden for the primary instance of the title. But that primary instance isn't identified to WordPress.

All this aside, there is still the issue of creating empty non-semantic headings, which negatively effects SEO and Accessibility.

Fabian Wolf

With the correct ID (for the current post - ie. the one that is called in the GET query) one could fetch its post and thus its post_title, then compare it AND the id when filtering the_title (which I assume the plugin does); also see https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-includes/post-template.php#L158

The main issue here probably is, that you have to check for the current context - maybe this would be a good idea for a new petition? Something like a function that tells us in what context the current part of PHP is running; eg. main content / The Loop, sidebar / widget area, wp_head, wp_footer etc. Else one has to do all of that manually, which can turn in a beautiful, but nasty nightmare.

cu, w0lf.

Greg Schoppe

Yes, the context is what I was describing when I referred to one of the instances of post_title being the "primary title". However, for this case it would need to be more specific than just "the loop" vs "the sidebar". Page builders will often pull in other posts, and everything in the page builder is technically in the loop. So hiding the title when in the loop context doesn't really help us.

It really boils down to a very explicit need for a conditional that you can put around the title and any wrapping elements, that effectively asks the post "this is the primary title of the post. Do you want to display it?"

Jimmy M. Coleman

Sorry I haven't had time to keep up. This is what I use and feel very comfortable with: https://wordpress.org/plugins/hide-title/

I will have a bit mor time in October, and I will try it in a testbed and see what happens. I think around mid-October, I need to read up on a few this in particulat to ClassicPress.