# api.onPageChange not working with endless scroll

**URL:** https://meta.discourse.org/t/api-onpagechange-not-working-with-endless-scroll/179636
**Category:** Development
**Created:** [February 14, 2021, 7:16am UTC](https://meta.discourse.org/t/api-onpagechange-not-working-with-endless-scroll/179636 "2021-02-14T07:16:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [February 14, 2021, 7:16am UTC](https://meta.discourse.org/t/api-onpagechange-not-working-with-endless-scroll/179636/1 "2021-02-14T07:16:17Z")

</div>

I’m trying to change the tag links using the below and it seems to work on refreshing the page or going to a new page, but it does not work when you scroll down the page where endless scroll loads in new items:

```js
<script type="text/discourse-plugin" version="0.8">
	api.onPageChange(() =>{
		var tags = document.getElementsByClassName("discourse-tag");
		for (i = 0; i < tags.length; i++) {
			var tag = tags[i];
			var url = tag.href;
			var newUrl = "https://site.com" + url;
			tag.href = newUrl;
		}
	});
</script>

```

Do I need to use something other than or in addition to `api.onPageChange`?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 14, 2021, 11:26am UTC](https://meta.discourse.org/t/api-onpagechange-not-working-with-endless-scroll/179636/2 "2021-02-14T11:26:52Z")

</div>

Yeah that won’t work. It’s only going to fire on a route change. You need to consider overriding the code that actually renders those tags directly rather than using Dom selection.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [February 14, 2021, 10:05pm UTC](https://meta.discourse.org/t/api-onpagechange-not-working-with-endless-scroll/179636/3 "2021-02-14T22:05:00Z")

</div>

Thanks Robert - I was hoping a something simple would suffice! 🙈

It’s been a while since I read the plugin guide but from memory it goes something like this?

- rails g plugin NAME
- locate the file you want to change
- copy it into the same directory in your plugin
- make your changes

However this is not working for me.

Editing this file directly (on line 29): [discourse/app/assets/javascripts/discourse/app/lib/render-tag.js at bbe5d8d5cf1220165842985c0e2cd4c454d501cd · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/bbe5d8d5cf1220165842985c0e2cd4c454d501cd/app/assets/javascripts/discourse/app/lib/render-tag.js) has the desired effect, but when I duplicate the file in the following location it has no impact `plugins/my-plugin/app/assets/javascripts/discourse/app/lib/render-tag.js`.

Any ideas what I’m doing wrong? Has something changed since I read the guides perhaps? (For some reason I thought it was as simple as overriding files to change small things like this).

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 15, 2021, 8:41am UTC](https://meta.discourse.org/t/api-onpagechange-not-working-with-endless-scroll/179636/4 "2021-02-15T08:41:18Z")

</div>

You don’t need a plugin, this is client side. Use a Theme Component.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [February 15, 2021, 3:52pm UTC](https://meta.discourse.org/t/api-onpagechange-not-working-with-endless-scroll/179636/5 "2021-02-15T15:52:57Z")

</div>

Thanks! Funnily enough I started customising the [Tag Icons](https://meta.discourse.org/t/tag-icons-component/109757) last night and managed to get it to work! 😃

Out of curiosity tho, should the plugin file-override method as I described above should have worked as well? (If so any ideas what I was doing wrong?)
