# Plugin Development Bug - InsertBefore Runs Twice

**URL:** <https://forum.pinegrow.com/t/plugin-development-bug-insertbefore-runs-twice/7371>\
**Category:** Plugin Development\
**Created:** [December 11, 2022, 11:47am UTC](https://forum.pinegrow.com/t/plugin-development-bug-insertbefore-runs-twice/7371 "2022-12-11T11:47:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![smemis](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@smemis](https://forum.pinegrow.com/u/smemis)\
**Post date:** [December 11, 2022, 11:47am UTC](https://forum.pinegrow.com/t/plugin-development-bug-insertbefore-runs-twice/7371/1 "2022-12-11T11:47:33Z")

</div>

I am writing a simple plugin. In the code below, insertBefore runs 2 times and creates 2 elements. I couldn’t find a solution. I will be glad if you can help me how to fix it.

Thank you.

var things = new PgComponentType(‘krft.things’, ‘THINGS’);  
things.selector = function ($el) {  
return true  
};  
things.display\_name = ‘tag’;  
things.not\_main\_type = true;  
things.sections = {  
‘krft.things’: {  
name: ‘THINGS’,  
fields: {  
‘krft.things.checkbox’: {  
type: ‘checkbox’,  
name: ‘Convert to Shortcode’,  
action: ‘custom’,  
value: ‘1’,  
set\_value: function (pgel, value) {  
var strBefore1 = ‘``’;  
var xcode = pgCreate(strBefore1);  
console.warn(xcode);  
**xcode.insertBefore(pgel);**  
return value;  
}  
}  
}  
}  
};  
framework.addComponentType(things);

---

<div class="post-metadata">

**Author:** ![smemis](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@smemis](https://forum.pinegrow.com/u/smemis)\
**Post date:** [December 11, 2022, 12:23pm UTC](https://forum.pinegrow.com/t/plugin-development-bug-insertbefore-runs-twice/7371/2 "2022-12-11T12:23:39Z")

</div>

The same problem exists with insertAfter, append, prepend methods
