Remove wrong dashes from get_the_title()

I have a particular CPT post that has a dash (-) in its title. I copy this title in a variable $var using get_the_title() then I create a custom field somewhere else with a value equal to $var : add_post_meta($my_post_id, 'some_name', $var);

Problem: in the custom field, the dash became a HTML entity with a “&”, “#” and a 4-digit number number.

Read More

Why, and how to fix the problem?

Related posts

Leave a Reply

1 comment

  1. get_the_title() is treated with wptexturize() by default. That changes the dash.

    To fix it remove the filter and reapply it if it was really set:

    $wptexturize = remove_filter( 'the_title', 'wptexturize' );
    $title       = get_the_title();
    
    if ( $wptexturize )
        add_filter( 'the_title', 'wptexturize' );