This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Using Custom JavaScript Code into WordPress Websites

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I wish to create a custom promo code generator based on JavaScript. However, I am not if it would work with WordPress. The basic idea is to implement the generator into WP posts.

Does anyone has every has tried it? Any reference would work.


Regards,
Jay
 
Saloon Keeper
Posts: 6630
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difficulty adding custom JavaScript code to each WP page (by adding it to the common header or footer include file), if that's what you're asking.
 
Marshal
Posts: 25946
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:There is no difficulty adding custom JavaScript code to each WP page (by adding it to the common header or footer include file), if that's what you're asking.



This is provided you're running your own Wordpress server. If you're asking how to do that to a page hosted on wordpress.com, then you can't include JavaScript in your posts or pages.
 
Tim Moores
Saloon Keeper
Posts: 6630
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I guess it depends on the kind of hosting you have. Through the WP admin pages on my hosted WP it's possible to edit all pages.
 
Paul Clapham
Marshal
Posts: 25946
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I can put JavaScript in my pages in my wordpress.com site. But whatever it is in wordpress.com which renders the pages for display, it strips out all of the JavaScript. At least it did eight years ago when I tried to put Google Maps code in some of my pages -- maybe they've changed since then.
 
Jay Gummers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Tim Moores wrote:There is no difficulty adding custom JavaScript code to each WP page (by adding it to the common header or footer include file), if that's what you're asking.



This is provided you're running your own Wordpress server. If you're asking how to do that to a page hosted on wordpress.com, then you can't include JavaScript in your posts or pages.



Yes, I am hosting the website on my own VPS hosting server. As for the code, do I need to paste it in the theme header.php ?  
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have to paste the javascript code in the post page rather than in header.php. I think you can automate this with the plugin?
 
Tim Moores
Saloon Keeper
Posts: 6630
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which page should contain the script obviously depends on which pages need it. There are probably plugins that can add scripts to particular pages, but altering the header is the quick way to add them to all pages. Note that upgrading WP will clobber changes made that way, do you need to re-add the code after upgrades.
 
Jay Gummers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Which page should contain the script obviously depends on which pages need it. There are probably plugins that can add scripts to particular pages, but altering the header is the quick way to add them to all pages. Note that upgrading WP will clobber changes made that way, do you need to re-add the code after upgrades.



I have recently upgraded to WP 5.0 (the one with the terrible Gutenberg). However, I don't think they'd be releasing any other update pretty soon.
 
Tim Moores
Saloon Keeper
Posts: 6630
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are new WP releases quite frequently. 5.0.1 is already out, and 5.0.2 probably not far away. Such dot releases should be installed ASAP, as they contain security fixes. Just something to keep in mind when making changes to the PHP code. But as noted, there may be plugins that achieve the same objective without being clobbered by updates.
 
Jay Gummers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the features that bad, I don't think I'd be upgrading anytime soon. Disabled auto update from the Settings.
 
Beatrix Lugo
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, is your issue got resolved?
 
Jay Gummers
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Beatrix Lugo wrote:Hey, is your issue got resolved?



Yes, I found a similar design of the generator on this website. So I scraped off the JavaScript from the website and gave it some personal touch.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic