• Resolved architecb33

    (@architecb33)


    Hi there!
    i am super thankful for this plugin.
    i am using it for app building using Ionic 2 & WP API.
    can you help me with this :
    i need to change the way your icon links to file programatically,

    from <a href="https://some-url/file.docx" target="_blank">

    to <a onclick="window.open('https://some-url/file.docx', '_system')">

    or <a (click)="openPage({target: '_blank', url: 'https://some-url/file.docx', extra_classes:'system'})">

    any help will be greatly appreciated ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Dan Rossiter

    (@danrossiter)

    Hi architecb33,

    You can definitely change the output of DG the way you describe with a little bit of PHP. You’ll want to setup a filter like the following (untested since I’m not at my dev computer right now, but should be close):

    add_filter('dg_icon_template', 'dg_href_to_onclick');
    function dg_href_to_onclick($icon, $use_descriptions, $id) {
        return preg_replace('<a [^>]*>', "<a onclick=\"window.open('%link%', '_system')\">", $icon);
    }

    -Dan

    Thread Starter architecb33

    (@architecb33)

    thx for the reply!
    the code doesn’t work,
    i get this error :

    Warning: Missing argument 2 for dg_href_to_onclick() in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 22
    
    Warning: Missing argument 3 for dg_href_to_onclick() in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 22
    
    Warning: preg_replace(): Unknown modifier ']' in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 23
    
    Warning: Missing argument 2 for dg_href_to_onclick() in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 22
    
    Warning: Missing argument 3 for dg_href_to_onclick() in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 22
    
    Warning: preg_replace(): Unknown modifier ']' in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 23
    
    Warning: Missing argument 2 for dg_href_to_onclick() in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 22
    
    Warning: Missing argument 3 for dg_href_to_onclick() in /home/gravig5/public_html/propertigo/wp-content/themes/ion-ap3-child/functions.php on line 22
    Thread Starter architecb33

    (@architecb33)

    Hello,
    Still waiting for the solution..
    Thankyou ??

    Plugin Author demur

    (@demur)

    Hi architecb33!

    Dan’s code slightly amended should work just as You need it ??

    function dg_href_to_onclick($icon, $use_descriptions, $id) {
        return preg_replace('/<a [^>]*>/', "<a onclick=\"window.open('%link%', '_system')\">", $icon);
    }
    add_filter('dg_icon_template', 'dg_href_to_onclick', 10, 3);

    Please don’t hesitate to let us know if You run into any further issues.

    Thread Starter architecb33

    (@architecb33)

    Works like a charm!
    Thanks Dan & Demur ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘change href to onclick’ is closed to new replies.