• Resolved pguilha

    (@pguilha)


    Hi,

    A few months ago I posted this question here (https://www.ads-software.com/support/topic/user-submitted-hyperlinks-randomly-broken/) and we never figured out what the issue was.
    Briefly, when some users insert some hyperlinks into the body of their listing, the link is broken in the published ad, with some added quote marks inserted, eg: https://example.com/en became ””//example.com/en/”””
    This happened once in a while, not for every ad and not for every link within an ad.

    I recently found out that what is happening is that the following characters %E2%80%9D are getting inserted within the links, and these encode double quote marks.

    From some googling it seems this might be caused by users copy/pasting hyperlinks from word or webpages, but surely there must be a way to automatically prevent this?

    Any suggestions? Could I change some settings in the WP editor?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hmm, you could try experimenting with something along these lines in your child theme’s functions.php (this allows pasting in rich text, while stripping unwanted elements, but may be could be inspiration for what you’re looking for):

    // Enable rich text to be pasted into TinyMCE fields
    
     add_filter( 'submit_job_form_wp_editor_args', function( $args ) {
            // Comment these lines to ENABLE the feature
    	// unset( $args['tinymce']['paste_auto_cleanup_on_paste'] ); // I would keep this enabled
    	 unset( $args['tinymce']['paste_as_text'] );
    	// unset( $args['tinymce']['paste_remove_spans'] );
    	// unset( $args['tinymce']['paste_remove_styles'] );
    	// unset( $args['tinymce']['paste_remove_styles_if_webkit'] );
    	// unset( $args['tinymce']['paste_strip_class_attributes'] );
    	return $args;
    } );
    
    // Remove, strip, and replace tags when content is pasted into TinyMCE
    
    add_filter('tiny_mce_before_init', 'customize_tinymce');
     
    function customize_tinymce($in) {
      $in['paste_preprocess'] = "function(pl,o){ 
      // remove the following tags completely:
        o.content = o.content.replace(/<\/*(applet|area|article|aside|audio|base|basefont|bdi|bdo|body|button|canvas|command|datalist|details|embed|figcaption|figure|font|footer|frame|frameset|head|header|hgroup|hr|html|iframe|img|keygen|link|map|mark|menu|meta|meter|nav|noframes|noscript|object|optgroup|output|param|progress|rp|rt|ruby|script|section|source|span|style|summary|time|title|track|video|wbr|table|tbody|tr|td|th|h1|h2|h3|h4|h5|h6|hr|big|code|font|blockquote|dir|address|cite|del|dfn|ins|kbd|q|samp|small|strike|sub|sup|tt|var|caption|input|dialog|fieldset|pre|a name)[^>]*>/gi,'');
      // remove all attributes from these tags:
        o.content = o.content.replace(/<(div|p|b|strong|i|em|ul|li|dt|dd|dl|u|s) [^>]*>/gi,'<$1>');
        
      // keep only href in the a tag (needs to be refined to also keep _target and ID):
        o.content = o.content.replace(/<a [^>]*href=(\"|')(.*?)(\"|')[^>]*>/gi,'<a href=\"$2\">');
      // replace br tag with p tag:
        if (o.content.match(/<br[\/\s]*>/gi)) {
          o.content = o.content.replace(/<br[\s\/]*>/gi,'</p><p>');
        }
      // replace div tag with p tag, b tag with strong tag, and i tag with em tag:
        o.content = o.content.replace(/<(\/)*div[^>]*>/gi,'<$1p>');
        o.content = o.content.replace(/<(\/)*b[^>]*>/gi,'<$1strong>');
        o.content = o.content.replace(/<(\/)*i[^>]*>/gi,'<$1em>');
      
      // remove double paragraphs:
        o.content = o.content.replace(/<\/p>[\s\\r\\n]+<\/p>/gi,'</p></p>');
        o.content = o.content.replace(/<\<p>[\s\\r\\n]+<p>/gi,'<p><p>');
        o.content = o.content.replace(/<\/p>[\s\\r\\n]+<\/p>/gi,'</p></p>');
        o.content = o.content.replace(/<\<p>[\s\\r\\n]+<p>/gi,'<p><p>');
        o.content = o.content.replace(/(<\/p>)+/gi,'</p>');
        o.content = o.content.replace(/(<p>)+/gi,'<p>');
      }";
      return $in;
    }

    Most of this is from here (with improvements). Some seems to work, some doesn’t–I’m not familiar enough with RegEx to perfect it, unfortunately.

    Thread Starter pguilha

    (@pguilha)

    Thanks @hastibe this looks promising. Do you know where I can find what the current tinyMCE settings are? I’d like to know what the current baseline I’m working with is.
    thanks again

    Plugin Support bindlegirl (a11n)

    (@bindlegirl)

    I’m marking this as resolved since it’s been over 2 weeks with no response. If you still need help with this, please feel free to mark it ‘not resolved’ again.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘broken hyperlinks in job listings’ is closed to new replies.