• Guyinpv

    (@guyinpv)


    Others have reported this, but it’s still an issue. The plugin hasn’t had an update in over a year. I don’t know if it will ever be fixed so I’m giving people my solution.

    When a post title has an “&” character in it, it will fail to work. This is because the code is reading the post title from the $post->post_title variable, and it’s also getting the post title from the hook ‘the_title’. The code then compares these two titles and if they match, then the code runs to hide the title.

    The problem is, $post->post_title would return “This & That” while the ‘the_title’ hook would return “This & That”. The compare would fail, and the post is skipped.

    To fix this, you have to normalize the titles so they can be compared. Update the plugin code in two places:

    Find this line: “$this->title = $post->post_title;”
    And change it to this:
    $this->title = sanitize_title_with_dashes($post->post_title);

    Then find this function:
    public function hpt_hptwraptitle($hptcontent) {……
    And add this line right inside the function at the top:
    public function hpt_hptwraptitle($hptcontent) {
    $hptcontent = sanitize_title_with_dashes($hptcontent);

    The function sanitize_title_with_dashes() is a WordPress function that makes a unique slug out of a post title. It should end up converting both versions of the title into the same slug where they can be compared properly and it will work again. It will work against any kind of special characters or spaces because it normalizes to just lowercase letters, dashes, and underscores.

    If they never update this plugin again, I don’t mind editing the core code of it. But if they do update the plugin, hopefully this fix will be in there and we won’t need the custom edit anyway.

  • You must be logged in to reply to this topic.