• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Using Custom JavaScript Code into WordPress Websites  RSS feed

 
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: 5132
135
  • 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.
 
Sheriff
Posts: 23968
50
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: 5132
135
  • 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
Sheriff
Posts: 23968
50
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: 5132
135
  • 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: 5132
135
  • 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.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!