We help IT Professionals succeed at work.

Wordpress Add Script to Page

notcjw
notcjw asked
on
Medium Priority
72 Views
Last Modified: 2020-02-26
I am relatively new to Wordpress and am trying to add code to a page.
Here is the code:

<div id="libchat_97a02353a0afcdc8a5eab67b19250e53"></div><script type="text/javascript" src="https://v2.libanswers.com/load_chat.php?hash=97a02353a0afcdc8a5eab67b19250e53"></script>


Although I have worked with PHP, javascript, and html extensively, I am at a loss on how to get Wordpress to recognize this code. I use the html editor on the page and the result is it simply displays the code, it should display a widget.

Any tips would be greatly appreciated.
Comment
Watch Question

Are you using a theme?  Can you supply a URL?  When you were editing the page, did you change from Visual to TEXT? top right corner of the WYSIWYG.  That changes it to a code view.  Any additional information wil be helpful.
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
Generally if you are able to use the "Classic" editor, then you can switch from the default Visual mode to Text mode (as Robert Granlund said), where HTML code should be interpreted as HTML and not just displayed as source code. The script tags will probably work from there too, but if not, there are other relatively easy options for that. Let us know how you go.

Screenshot below.

Note that many sites use a visual editor of some sort (eg Elementor, Gutenberg, etc), and in some cases the Classic editor is disabled. If that's the case, we may need to look at other options.

WordPress Classic editor

Author

Commented:
Thank you for the input. Apologies for getting back sooner.

Here is URL:   https://library.sage.edu/chat/


When I switch to the code editor.  Below is relevant code. Note that CODE1 points to the widget
I cannot figure out where CODE1 is stored.


<table>
<tbody>
<tr>
<td width="160" height="280">%CODE1%</td>
</tr>
</tbody>
</table>

Author

Commented:
THEME: Responsive Child Theme

Author

Commented:
Searching CODE1 brought me to this page. See image.

I cannot figure out how to edit it though.

Author

Commented:
codeembed.png
You may need to use a shortcode.  However upon testing it looks like it is showing for you.

Author

Commented:
I would like to edit the code that  CODE1 refers to  but I cannot figure out how do it. The "Code Embed Search" brings me to the page above but I cannot edit the code it displays.  I am really inexperienced with Wordpress.
OH!  OK, what is the name of the plugin?  We can start there.
Questions:
1. Do you want to change the functionality of the Chat?
2. Do you want to change the way the Chat looks?

Author

Commented:
Thanks for all your help with this. Ti think I need to change the functionality of the chat.  I am not sure which plugin would be involved. Poking around, I keep coming across "Code Embed" and "Maligun" but I am not sure how they are involved.


What I need to do is to change this this script which CODE1 points to:

<div id="questionpoint.chatwidget1" qwidgetno="1" ></div>
<script id="questionpoint.bootstrap1" qwidgetno="1" type="text/javascript" src="http://www.questionpoint.org/crs/qwidgetV4/js/qwidget.bootstrapnj.js?langcode=1&instid=13659&skin=green&size=fill" charset="utf-8">//<noscript>Please enable javascript to chat with librarians online</noscript></script>



To this script:

<div id="libchat_97a02353a0afcdc8a5eab67b19250e53"></div><script type="text/javascript" src="https://v2.libanswers.com/load_chat.php?hash=97a02353a0afcdc8a5eab67b19250e53"></script>

Author

Commented:
This is the URL of the page that I need to change:

https://library.sage.edu/chat/


Also, the code  is referred to on sidebars throughout the site. For example, the second block of the right sidebar here:

https://library.sage.edu/databases/arts/
OK, sign into WordPress.
Click Appearance > Widgets.
On the right side look for a Text Widget and open it and see if you can find the code there? This will be for the Sidebar.

The main page with the chat looks like it is embedded on the Post.  Go to Posts > All Post ad find "Chat".  It may be on that page

Author

Commented:
I found the sidebar code, which is much the biggest issue. Thank You!  You have no idea how helpful this is.


As for CODE1. There is no Chat post. Chat is a page, which contains the line


<td width="160" height="280">%CODE1%</td>

I think I can just replace this line with actual code CODE1 points to and that will solve the problem; although I still would like to know where I could edit CODE1 directly.

I just took over managing this site and  we are switching the code on Friday.
Can you click on Chat, Chatty or Copy Chat?  Can you send a larger screen grab? I am not really sure where that is in you admin.  I'm not sure what I am looking at in the screen grab above.
In the administration menu is there a settings option named “Code Embed”?  If so, click that and go through the options and you may find it there.

Author

Commented:
Larger screen grab of code seach attached.
codeembedsearch2.png

Author

Commented:
Attached is the chat page that opens when clicking on the link in Code Embed Search.
In the administration menu is there a settings option named “Code Embed”?  If so, click that and go through the options and you may find it there.

Author

Commented:
Attached are the screen shots from the CODE EMBED page.  One is from the top of the page and the other from the bottom.

The bottom of the page refers to a custom field. If I could find the custom field, i think that would be the solution.
codeembed1_topofpage.png
codeembed2_bottomogpage.png
Go to the Page Chat > Find "Custom Fields" and open that.  If it is not present, go to the top of the page and click "Screen Options"  and click Custom Fields. Go to the Custom Field and you should see it there.

There are some Screen Shots and the end of this link.  (Keep this link)
https://wordpress.org/plugins/simple-embed-code/#description
Commented:
That would appear to be the solution. I think I have to add the the "Advanced Custom Fields" plugin. I have to run this by my IT department who need to review plugins.


This has been extremely helpful. Problem solved!!!

Author

Commented:
Both experts were extremely helpful.  I have no Wordpress experience and just took over the web site.  Robert's guidance was invaluable navigating the tricky way the website was  set up and ultimately fixing the problem.
No worries.  I'm glad to help.  Many many years ago I was in your same situation and some very kind and helpful experts guided me on my way.  I'm glad I could give back.