In this article I’m going to discuss the process of adding a bit of JavaScript code into a PHP-Fusion article.
This process is going to take advantage of the built-in add_to_head output handling function that is available in PHP-Fusion. There are also other output handling functions like add_to_footer and add_to_meta that allow you to perform similar actions on your content. You can see the full list of PHP-Fusion functions like this that are built-in on the PHP-Fusion 8 Development & Project site.
Adding JavaScript to a PHP-Fusion article
Using the steps below, I’ll walk you through the process of getting a simple JavaScript alert pop-up to function within one of your PHP-Fusion articles.
- Login to the PHP-Fusion admin panel.
Click on Articles.
I have gone ahead and filled in the Subject, Snippet, and the Article content with the following text:
Subject | JavaScript Hello! |
---|---|
Snippet | Make JavaScript say Hello! |
Article | In PHP-Fusion we can add JavaScript to provide extra functionality to the site! <p style=”display:none;”> |
You should notice that around the JavaScript code, I have added a <p style=”display: none;”> style to the paragraph tag to completely hide the JavaScipt code. Without this, the JavaScript code would still run on the page, however you’d still see the text add_to_head(”) displayed in the article.
Now when we access the article that we added this JavaScript code to, we successfully see that the JavaScript code is run in our web-browser, and a pop-up message is displayed with our text.
You should now know how you can get JavaScript code successfully added to one of your PHP-Fusion articles.