[Support request] PHP filtering questions (title tag and headings)

Home Forums Support PHP filtering questions (title tag and headings)

  • This topic has 8 replies, 2 voices, and was last updated 2 weeks ago by David.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1443536
    Eric

    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

    #1443726
    David
    Staff
    Customer Support

    Hi 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.

    #1444045
    Eric

    Hey 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.

    #1444070
    David
    Staff
    Customer Support

    I 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.

    #1444110
    Eric

    Hmmm 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?

    #1444140
    Eric

    BTW the headings fix worked like a charm! Thank you!

    #1444357
    David
    Staff
    Customer Support

    I 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 ?

    #1444523
    Eric

    Wow 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!

    #1444548
    David
    Staff
    Customer Support

    You’re welcome – let us know if Yoast decide offer up any assistance.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.