Skip Navigation

[Closed] Programmatic changes to titles and headers for one CPT

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 2 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2428421

Tell us what you are trying to do?
I've had this issue for a long time, and anything I've tried with CSS and PHP hasn't worked. I have over 1400 posts in my 'reports' CPT. The titles are "[trailname] [datestring]" like "Eagle Rock 220410" that represents the Eagle Rock trail that we did on April 10, 2022. I don't want to change all of the titles as that information is used to pull in galleries, and we've done the Eagle Rock trail many times on other dates. Instead, I want to display "Eagle Rock" as the title without that date stamp. It should also show as "Eagle Rock" as the title in Google searches, and other areas.

Second, the header on the page has been replaced with a custom header. When the page first loads, the WP header and the replacement header show up. Then the WP header does not display as CSS kicks in. Is there a Toolset way to hide the WP header from the start for this CPT?

Is there any documentation that you are following?
Just the Toolset docs.

Is there a similar example that we can see?
The best way is to load a page that is not cached. If you go to hidden link and click on any of those images, you will likely load a Report that is not cached. Watch the header area to see both appear and then the top one hidden. I won't load any of these, so you can try it. The title is the other thing to observe, and you can see that issue on any Report page.

What is the link to your site?
hidden link

#2428791

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Actually the problem you shared is more related to how SEO works or how to change the tittle from title+date to only title.

You can override the title when you want to display using programming. If you are using Yoast SEO plugin here is the article that shows how you can change the title using filter hook "wpseo_title":
=> hidden link

#2428959

I'm not using that plugin but maybe I should be -- thanks for that link to change the titles for that CPT.

For the second part of my question, I'm guessing that Toolset can help me hide the original page header (that title+date and other links to edit the page, etc.) so it never displays -- to never show it at all. I think if I can accomplish that (instead of hiding it after the fact with CSS) then I'd be set.

Thanks, Minesh!

#2429521

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry, do you mean that you want to hide the title input box when you edit the post in the backend or you want to hide the title that is displayed from the theme on frontend?

#2429883

I want to be able to enter title+date as the title in the backend like I do now. I need to have it that way for other things to work properly. An example is at hidden link where the title, as entered, is "Eagle Rock 220410" (in this case).

When the page loads now, it sets "Eagle Rock 220410 - TrailDamage.com" as the title, and I was hoping to change it to "Eagle Rock on April 10, 2022 - TrailDamage.com" somehow. It sounds like Yoast SEO can do that, and I'm still researching it (thanks for the tip!).

When the page loads now, it will also set the header to this:

<h1 class="entry-title" itemprop="headline">Eagle Rock 220410</h1>

This matches what I have the title set to, as it should. I'm using CSS to hide that H1 so I can replace it with my own H1. Of course, that usually means you can see both H1s for a second or two before the original one is hidden. Can Toolset help me change the H1 programmatically, so it never shows up at all (and I don't need CSS to hide the original)?

It is a customization only for this CPT, so I don't want to change titles and H1s across the whole site.

Thank you!

#2430169

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To hide the header, You should edit your theme's CSS file or customizer that allows you to add custom CSS and try to add the following CSS code:

.single-reports .entry-header { display: none; }
#2430831

Yes, that is exactly what I'm doing now and it works, but there is a second or half-second when you see both titles. This is before the CSS runs. Does this mean Toolset can't hide the title on the server side before the HTML is delivered? That's fine if it doesn't -- I'm just confirming.

#2430907

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - the CSS I shared should be added to your theme's CSS file so that it will be added to the header before the page is loaded and that should fix the issue.

If you want me to login and check whats going wrong, I'm happy to login and adjust it.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

The topic ‘[Closed] Programmatic changes to titles and headers for one CPT’ is closed to new replies.