Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

I want to run JavaScript on my pages

  • #7537
    Avatar photo[anonymous]

    Hello,

    I’ve got some JavaScript doodads I want to run on my pages. They’re basic and self-contained scripts.

    I went looking for some information on this. I found https://getpublii.com/dev/how-to-add-custom-config-or-js-for-post-editor/  but I wasn’t sure if that was applicable to what I want to do.

    Am I missing the correct documentation? If someone can point me in the right direction I’ll take a pop at figuring it out myself.

    thank you.

    #7538
    Avatar photoBob

    Just use the Custom HTML tool → https://getpublii.com/docs/tools.html#customhtml

    #7539
    Avatar photo[anonymous]

    I’m sorry, I’m not sure that applies to what I’m doing. I want to put different scripts on different posts. This looks like it’s for HTML sitewide?

    You must think I’m quite stupid, I apologize.

    #7540
    Avatar photoBob

    I’m afraid, by default there is no way to put different scripts on different post pages.
    Custom HTML tool places your script/s in dedicated rooms like header, footer, body …

    You will have to play around with the post config option to create a dedicated “room” for your scripts and then you will be able to paste different codes into different posts.
    More about it: https://getpublii.com/dev/post-config-options/#post-config-options

    #7541
    Avatar photo[anonymous]

    Thank you. Would the simplest thing be to put all my scripts in one js file and apply that globally using the Custom HTML tool? They’re already set up as functions.

    #7542
    Avatar photoBob

    Upload your e.g. script_name.js using File Manager, then use the Custom HTML tool (move it to the footer) to add this file as follows:

    <script src="../../media/files/script_name.js"></script>
    #7543
    Avatar photo[anonymous]
    This reply has been marked as private.