5

I have problem in Wordpress after migrating my website. In title tag (<title>) I have "&#8211;" instead of "-"

For the browser it's good, in the title it shows good. But in html code is "&#8211;"....

Please help me <3

  • "& # 8 2 1 1 ;" (but without spaces, i see this site changed it to "-" too). – incestweb Feb 20 '17 at 20:45
  • I dind't change the code. It's just a problem... I need normal working solution for problem – incestweb Feb 20 '17 at 20:50
  • wordpress 4.6.3 – incestweb Feb 20 '17 at 20:52
  • 1
    For WP 4.0+, add this CODE in your theme's functions.php file: add_filter( 'run_wptexturize', '__return_false' ); it'll disable all these conversions. – Fayaz Feb 20 '17 at 20:52
  • You are welcome. I've added more details in my answer. – Fayaz Feb 20 '17 at 22:14
1

Background:

WordPress converts normal dash (-) to long dash (), straight quotes to curly quotes and some other similar symbols and punctuations to their printer friendly versions using wptexturize.

Generally it's recommended to leave them up to WordPress. However, occasionally, we may want to override this behaviour. For example, in case we are writing Programming CODE or command and want people to copy paste them.

Solution:

One way to avoid this conversion is to have these CODE inside <code></code> block. That way WordPress will know that they are meant to be kept as is. However, we may have already written it and don't want a rewrite. In that case, it's possible to stop WordPress to do these auto conversions all together by disabling wptexturize.

For WordPress 4.0 and above, it's easy to do using the following CODE in a plugin or your theme's functions.php file:

add_filter( 'run_wptexturize', '__return_false' );

For before WordPress 4.0, you'll need a little more CODE:

foreach( array(
    'bloginfo',
    'the_content',
    'the_excerpt',
    'the_title',
    'comment_text',
    'comment_author',
    'link_name',
    'link_description',
    'link_notes',
    'list_cats',
    'nav_menu_attr_title',
    'nav_menu_description',
    'single_post_title',
    'single_cat_title',
    'single_tag_title',
    'single_month_title',
    'term_description',
    'term_name',
    'widget_title',
    'wp_title'
) as $texturize_disable_for )
remove_filter( $texturize_disable_for, 'wptexturize' );

Of course, you may choose to disable wptexturize only for part of your content. Say, to disable only for title, you may use:

remove_filter( 'the_title', 'wptexturize' );
-2

Make sure that anything you are passing to the wp_title(); function is wrapped in esc_html();

Example:

<title><?php esc_html(wp_title($YOURSTRINGHERE)); ?></title>

This will properly convert any HTML entities to their appropriate equivalents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.