Home>Support>Image Widget: Destination Url Link attributes

Image Widget: Destination Url Link attributes

Hello there :D

I am using Google Analytics in order to track my page traffic. I want to track my outbound links as well. Which works if I add the “onclick” attribute to my links. However, I have not found a way to add this attribute to the destination URL of the Image Widget.

I am using the Image Widget in order to display ads. So the destination URL leads the User to the homepage of the advertisor. I want however, to also track how many people are clicking on the image.

Here is the google analytics thread about how to track outbound links:
https://support.google.com/analytics/answer/1136920?hl=en

Is it possible to use that tool for the Image Widget as well? If so, how do I manage to add those attributes to the destination URL?

Thanks for your help!

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 8 years, 1 month ago Nico

    Hello there. I was investigating and found out that it is possible to extend existing widgets from SiteOrigin. See https://siteorigin.com/docs/widgets-bundle/getting-started/extending-existing-widgets/.

    I tried to adjust the image widget so that I could add the “onlick variable” to the URL. This is what I came up with:

    I copied the subfolder “image” in /plugins/so-widgets-bundle/widgets and renamed it to “werbung”. Then I opened image.php, renamed it to werbung.php and made no changes to the code, except renaming it in the first few lines.

    Afterwards, I opened /tpl/default.php and made the following changes (on line 46):

    [/code]

    <a href="”onclick=”trackOutboundLink(”); return false;” >

    .
    
    However, If I try to load the page, all the page gets white. If I remove the folder "werbung", it works again. Is it because I left out the following part:
    
    
    

    function mytheme_extend_button_form( $form_options, $widget ){
    // Lets add a new theme option
    if( !empty($form_options[‘design’][‘fields’][‘theme’][‘options’]) ) {
    $form_options[‘design’][‘fields’][‘theme’][‘options’][‘test’] = __(‘Test Style’, ‘mytheme’);
    }

    return $form_options;
    }
    add_filter(‘siteorigin_widgets_form_options_sow-button’, ‘mytheme_extend_button_form’, 10, 2);

    I did not know where to put it as it was only described for the button widget, and I could not really figure out how to do it with the image widget. Thanks for your help!

  2. 8 years, 1 month ago Nico

    Sorry for the complete crap usage of the code variable up there :D I try it again here:

    Changes to tpl/default.php on line 46:

    <?php if(!empty($url)) : ?><a href="<?php echo sow_esc_url($url) ?>"onclick="trackOutboundLink('<?php echo sow_esc_url($url) ?>'); return false;" <?php if($new_window) echo 'target="_blank"' ?>><?php endif; ?>
    

    And the one I left out:

    function mytheme_extend_button_form( $form_options, $widget ){
        // Lets add a new theme option
        if( !empty($form_options['design']['fields']['theme']['options']) ) {
            $form_options['design']['fields']['theme']['options']['test'] = __('Test Style', 'mytheme');
        }
    
        return $form_options;
    }
    add_filter('siteorigin_widgets_form_options_sow-button', 'mytheme_extend_button_form', 10, 2);
    

    Thanks

  3. 8 years, 1 month ago Alex S
    Hi, I Work Here

    Hi Nico,

    I’m very sorry for the missing this.

    To clarify, as you’ve suspected; This isn’t possible by default – I’ll log it as a feature request.

    I would strongly recommend using JavaScript (specifically jQuery) instead of creating a custom widget as based on your code you don’t really need to do anything fancy with it.

    Regardless, I would not recommend editing a core plugin files as any changes will be lost on update. Instead, make a custom plugin as it’ll only take you a few minutes and it’ll prevent a headache down the line. Could you send me the full plugin files so I can see what you’ve done completely without having to copy code (and thus potentially create further issues). Please upload the export to a 3rd party file hosting site such as teknik.io.

  4. 8 years, 1 month ago Private Message - Nico

    This is a private message.

  5. 8 years, 1 month ago Alex S
    Hi, I Work Here

    Hi Nico,

    Oddly, I was able to use that version without it erroring. You should try enabling WP_DEBUG so that you can get a better idea of what is causing this issue.

  6. 8 years, 1 month ago Nico

    Hello. That is odd. I figured out where the problem was with the help of wp debug. It was because I forgot to rename the Widget properly in werbung.php, as it looks like. Thanks for your help anyway and I would love to see this feature in future updates!

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More