简体   繁体   中英

How to impliment this code on Wordpress site

I was wondering how i can implement this code on a Wordpress site, as when i add it nothing seems to happen, the code is implemented on this page :

<script>
    var links = $$(".feed-item a");
    for (var i = 0; i < links.length; i++) {
        links[i].onclick = function () {
            location.href = "/mypage.html";
        }
    }
</script>

Thanks

Put it inside <script></script> tags to tell the browser to interpret it as Javascript.

You can't have a hyphen - in a variable name, you could use camel case instead: var feedItem ;

Also you have a missing } to close the for loop.

Altogether it would look like this:

<script>
    var feedItem;
    for(var i = 0; i < links.length; i++){
        links[i].onclick = function() {
            location.href="/mypage.html"
        }
    }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM