- This topic has 36 replies, 3 voices, and was last updated 3 years, 4 months ago by David.
-
AuthorPosts
-
September 14, 2020 at 10:31 pm #1443536Eric
Hey GP Team! I hope you guys are all staying safe and well out there…
I had a few questions about filtering across my GPRESS site. display:none solutions will not work unfortunately so I am hoping there is a PHP solution instead? I would like to:
1. Filter out the <title> tag from all pages
I have already been able to stop Yoast from generating one, but even with it disabled I can still see a <title> tag in the code. It seems auto-generated and includes the site title along with it. Is there a way for me to filter it out completely site-wide?
2. Change all sub headings (h2, h3, h4, h5, h6) across the site into <p> tags
I want to be able to change these all out across the entire site and style them instead with a class. The only way I know how to do this is to search and replace and I’m concerned that I will have to revert back to headings again at some point! I’m hoping to use something like in place of the traditional h2, h3, h4, etc.:
<p class="headings3">
with style:
.headings3 { font-size:35px; font-weight:900; }
The tricky part of all of this is that I might have to retain some headings, and change out others. So if there’s a solution that will specifically replace each heading as needed that would be fantastic.
Anyways, I hope to hear from you soon and thank you guys for making the BEST WP theme in the world! #GPRESS4LYF
September 15, 2020 at 2:18 am #1443726DavidStaffCustomer SupportHi there,
1. Try this PHP Snippet to remove the
<title>
tag from the WP<head>
:remove_action( 'wp_head', '_wp_render_title_tag', 1 );
2. That sounds really complicated – you would have to filter
the_content
for example:function db_change_content_h2( $content ) { $content = str_ireplace( '<h2>', '<p class="heading-2">', $content ); $content = str_ireplace( '</h2>', '</p>', $content ); return $content; } add_filter( 'the_content', 'db_change_content_h2' );
You can string as many
$content = str_ireplace
within that function.Selectively choosing which is affected would be difficult. The way to do that would to make sure the <h2> element is different. eg. the above code would NOT affect
<h2 class="my-custom-class">
as the tag is different, however it will rely on WP to correct the closing</h2>
– which it may do perfectly well but can’t guarantee that it won’t mess up somewhere.September 15, 2020 at 6:43 am #1444045EricHey David, thank you for the response… unfortunately, this tag:
remove_action( ‘wp_head’, ‘_wp_render_title_tag’, 1 );
…it has no effect and the <title> tag is still in the code. I actually tried this out first before messaging you guys but for some reason it won’t work.
Noted on the headings solution, I’ll give it a go and let you know.
September 15, 2020 at 7:02 am #1444070DavidStaffCustomer SupportI tested that snippet on a clean install and it works.
Do you have an SEO plugin – that may be overriding the core function – let us know.September 15, 2020 at 7:20 am #1444110EricHmmm just Yoast but I’ve already filtered out the seotitle from there as well. I need to keep Yoast active on the site for it’s other features. I’ve tried this below:
add_filter( 'wpseo_title', '__return_false' ); remove_action( 'wp_head', '_wp_render_title_tag', 1 );
It filtered out the SEO title that you type in the post editor but it then still displays a <title> tag but then adds the sitename at the end as well. What do you suggest?
September 15, 2020 at 7:39 am #1444140EricBTW the headings fix worked like a charm! Thank you!
September 15, 2020 at 8:04 am #1444357DavidStaffCustomer SupportI found this:
https://wordpress.org/support/topic/_wp_render_title_tag-not-working/
Unfortunately they’re not very helpful with how to disable there new feature….
Maybe you have premium support with Yoast where they may be a little more co-operative ?September 15, 2020 at 9:51 am #1444523EricWow not very helpful is an understatement lol
OK thank you, I’ll try to figure it out over there. At the end of the day, maybe it would be best to just shut it off. Thanks again for the headings fix!
September 15, 2020 at 10:02 am #1444548DavidStaffCustomer SupportYou’re welcome – let us know if Yoast decide offer up any assistance.
October 7, 2020 at 6:07 am #1476370EricHey there David, sorry to unearth this ticket again… Just wanted to update that yeah no luck on the Yoast front unfortunately. But I did have a question about the headings swap code you gave me last time. I am currently trying to use it on h1 and it doesn’t seem to work. I would like to swap out all my h1 tags to h2 site wide (so that none of the pages has an h1 in the code). Unfortunately, when I try to use the php you gave me last time on h1s, it doesn’t work like on all the other headings. Here is the adjusted code I tried to use from what you gave me above:
function db_change_content_h1( $content ) { $content = str_ireplace( '<h1>', '<h2>', $content ); $content = str_ireplace( '</h1>', '</h2>', $content ); return $content; } add_filter( 'the_content', 'db_change_content_h1' );
What have I done wrong here exactly? Shouldn’t this swap them all out site wide like the others (h2, h3, h4, etc.)?
Anyways, thanks again for your time and attention and I hope you guys are all staying safe and healthy. Hope to hear from you soon!
October 7, 2020 at 8:23 am #1476806DavidStaffCustomer SupportTry this PHP Snippet:
add_filter( 'generate_get_the_title_parameters', function( $params ) { if ( is_singular() ) { $params = array( 'before' => sprintf( '<h2 class="entry-title"%s>', 'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : '' ), 'after' => '</h2>', ); } return $params; } );
October 7, 2020 at 10:05 am #1476998EricHmmmm ok I’ve tried it out but doesn’t seem to have any effect. The <h1> is still in the page code, and doesn’t change into an <h2>. Any other ideas?
October 7, 2020 at 11:22 am #1477147TomLead DeveloperLead DeveloperHi there,
That code should turn H1 elements to H2 elements on single posts and pages.
Are you using GP 3.0.0?
October 7, 2020 at 6:33 pm #1477642EricOh sorry about that! yes it was still on version 2.4.2… this code does work on version 3, thank you! Congrats on the latest version release by the way, the changelog is BANANAS! Thanks again guys… please stay safe and keep up the great work!
October 8, 2020 at 9:07 am #1478809TomLead DeveloperLead DeveloperAwesome, I’m glad we could help! Thanks, you as well 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.