• Resolved monitor

    (@oomskaap)


    Hi Gabriel,

    This is quite a head scratch problem.
    I know for a fact this feature works as I have tested it before. Not much have changed but it seems not not work anymore for some reason.

    I made sure it’s set to “No Limits”, so it will always give points.
    Yet when I click on a link it does not give points. I am sure my short-code is correct as below.

    I tested this same link on 5 other of our sites, with the same results.

    Take this link for example:

    <?php echo do_shortcode('[mycred_link amount="10" href="https://www.tumblr.com/" target="_blank"]<img src="https://i.minus.com/iK5BCVVzqsnK7.png" alt="" />[/mycred_link]'); ?>

    Or, even your example link:

    <?php echo do_shortcode('[mycred_link amount="10" href="https://www.merovingi.com" target="_blank"]View portfolio[/mycred_link]'); ?>

    Please keep in mind that I am certain these links worked a few days ago but I can’t get them to work anymore.

    Is there a different or a better way to show the links in your template other than a echo do_shortcode way?

    https://www.ads-software.com/extend/plugins/mycred/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author myCred

    (@designbymerovingi)

    For the points to be awarded the jQuery needs to be loaded. This is done in the footer to allow the shortcode to be placed “before” so they can request the script to be loaded. Check if you get any javascript errors on pages where the code does not work. See if the link script is loaded on the site. It’s located in mycred/assets/js/links.js

    Best place to start troubleshooting.

    Plugin Author myCred

    (@designbymerovingi)

    If it is not, add the following before your code:

    global $mycred_link_points;
    $mycred_link_points = true;

    That should trigger the script to be loaded in the footer.

    Thread Starter monitor

    (@oomskaap)

    Yes this was a custom page. Due to design, it does not have the regular theme’s header and footer.

    So I manually added:

    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js?ver=1.8.1'></script>

    <script type='text/javascript' src='https://www.xxxxxx.com/wp-content/plugins/mycred/assets/js/links.js?ver=1.1.1.1'></script>

    Then it still did not work.
    However, when i added this piece of code above these codes, it did work:

    <script type='text/javascript'>
    /* <![CDATA[ */
    var myCREDgive = {"ajaxurl":"http:\/\/www.xxxxxx.com\/wp-admin\/admin-ajax.php","token":"dfeb45d68a"};
    /* ]]> */
    </script>

    Now my question is, is this okay? Can that token stay static like this, or will it cause problems? I tried removing it but then it does not work any more. Seem it must have that code to work.

    Plugin Author myCred

    (@designbymerovingi)

    Ok. So it is the javascript that is not getting loaded.
    Do you use the wp_footer(); function on your footer?
    If this is a custom page where you know you will always have links that give points, then you would be better of just enqueue the script on this page. Then there will no need for the above fix.

    The reason I included this is because I dont want the javascript to be loaded on pages where the shortcode is not used.

    Example: Enqueue the script on page 2’s footer (requires that you use the wp_footer(); function on your page):

    add_action( 'wp_footer', 'load_mycred_link_script' );
    function load_mycred_link_script() {
    	if ( is_page( 2 ) ) wp_enqueue_script( 'mycred-link-points' );
    }

    Alternatively you can also load this script in the header:

    add_action( 'wp_head', 'load_mycred_link_script' );
    function load_mycred_link_script() {
    	if ( is_page( 2 ) ) wp_enqueue_script( 'mycred-link-points' );
    }

    Thread Starter monitor

    (@oomskaap)

    Unfortunately I do not use wp_footer(); on this custom page. And yes this page is solely made for links, so the scripts can run on it permanently.

    I will just stick to the token code, since it is working if i have that.

    <script type='text/javascript'>
    /* <![CDATA[ */
    var myCREDgive = {"ajaxurl":"http:\/\/www.xxxxxx.com\/wp-admin\/admin-ajax.php","token":"dfeb45d68a"};
    /* ]]> */
    </script>
    Plugin Author myCred

    (@designbymerovingi)

    I think you should enqueue the script in your header at least. When the script is included you also include ajax details. One of these are the ajax tokens that are generated. If you just copy and paste it in, it will stop working once the token is no longer valid.

    Thread Starter monitor

    (@oomskaap)

    It is working now. Sorry it was also mostly due to my lack of knowledge.

    Plugin Author myCred

    (@designbymerovingi)

    Ok. Let me know if that changes.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Points for clicking on links works..sometimes.’ is closed to new replies.