bobnwp
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Adding Javascript data table into my wordpress site@ravin, you are over complicating things.
Unless all of the code in the script files he needs to include (and that is all that the Register/Enqueue crap does) in the page is not inside functions – that is, if there is any open code, he can simply use wp_enqueue_script statements in one hooked function to get WP to include <script> tags for them in the page’s <head>.
WP will include jQuery so there is no need to specify it as a “depends upon” and he doesn’t need to use the wp_register_script function, he can get it done with just several wp_enqueue_script statements in the hooked function.
What I said abobe depends upon all code being in side functions, including his – more on that later:
What he should do is – in few words:
1. Register and Enqueue the scripts so that they are included in the <head> of the page via a hooked function, examples of which he has seen.
2. His own code, the beginning of the entire processing, should be contained in a function – for several reasons. For one reason, he can get a <script> inserted in the <head> via the wp_enqueue_script function to have the browser get the code file, and put the call to the function in the post where he wants the code executed. Otherwise he would be inserting all of the code in the post – messy – instead of just a call to a function.
3. – At the point he wants to execute the code, he uses the executeJavaScript shortcode I gave him –
[executeJavaScript code=”myfunction();”]
to insert:
<script>myufunctionname();</script>
into the post where he wants the code executed.
That should do the job.
He is fully responsible for the JavaScript working properly and for not introducing any security issues.
He would have to control who can post on his site so that someone else could make nefarious use of the shortcode BUT if they did, they would have to either get all their code in to the post with the shortcode or be able to call wp_enqueue_script to get a script included in the HTML for the post page.
That would require more access to the installation than most users are given.
If necessary, I can implement some security on the shortcode – some sort of password, hashed value, sort of things – I’ve only just thought of this and I’m not going to try and go into any details right now.
Forum: Fixing WordPress
In reply to: Site CSS/JS not working remotelyJason – you skip my remakrs to Jan and scroll down towards the bottom and look for a long dashed line – my comments to you start there. Or read the everything, your choice.
[unnecessarily long-winded personal remarks removed]
Jason
If you are still there and reading my replies ————
Go to your theme’s directory and search for frameset and see if you can find any instances in any of the files in any of the directories.
A good Windows program for such searching is Agent RanSack – don’t let the name scare you, it is cute playoff on the idea of someone search a house for something and “ransacking” it. Agent Ransack does nothing but search for files by name or partial name and it also can look in side files for strings you specify (and you can use regular expressions in the searching).
Go to https://www.mythicsoft.com/agentransack/download and click the big blue download button.
Save it to a directory (I have a Download directory under my Windows User and I make sub directories in it for things I download. For Ransack I would make the subdirectory: Agent Ransack
Run a virus scan on the downloaded file with whatever virus scanners you have installed (you do have at least one – right? and you keep them up-to-date – right) just to be on the safe side.
Then install it.
Start it up and then click the button that looks like a single file folder near the end of the line, on the right, that begins with “Look in” and navigate to your theme’s directory – the directory itself, not any file in it.
Then type:
frameset
in the box on the line that begins with “Containing text:” that is right above the “Look in:” line.Press enter and it will look in all files in the theme’s directory and subdirectories for the text: frames.
Any files containing the “frameset” will be listed. You can right click and chose a program, say NotePad, to open them with and look at the contents.
Let me know if you find anything. If you want, search the entire WP directory – all of the files and directories in the WP director to see if there is anything at all there.
BUT I suggest you go buy a hosting plan and use Duplicator to move the WP site to a hosting company’s server.
Bob
Forum: Fixing WordPress
In reply to: Adding Javascript data table into my wordpress siteMORE –
You said:
I copy and pasted the code from here
https://github.com/Zami77/GameStoreData/blob/gh-pages/index.html
Does that mean you copied all of the stuff shown on that page into a post or page on your WP site???
If so, that won’t work.
If you need custom CSS or HTML for your JavaScript to produce the correct output, you need to add that CSS and HTML to WP.
It was assumed, by Ravin and me, that you were asking merely how to execute JavaScript on a WP page.
If you need to add CSS and possible HTML, there is more you’ll have to do.
You can put the CSS in the theme’s style.css file, usually at the bottom of the file.
Make sure none of the rules duplicate ones already there.
A “rule” is the first part of a CSS specification, for example – body, .mydiv, #divwithid
If you do code a rule with the same name, whatever your code will replace what is already defined or will be added to the rule if what you specify is not already in the rule.
If you need some custom HTML, let me know what it is and where it needs to go.
Another question – I see:
<script src="graphic.js" type="text/javascript"></script>does that mean that your code is not in a function but is “open” code?
Bob
Forum: Fixing WordPress
In reply to: Adding Javascript data table into my wordpress siteAnother thing —
The code Ravin showed you, second example, for registering and enqueing the JavaScript script will only cause it to be loaded on “post” page.
If you want it to appear on a “page” (as opposed to a just a “post”),
remove the if and leave just the wp-register-script and wp-enqueue_script calls in the function.function wp_add_scripts() { // name_of_script_you_want_to_give, path_of_script_template_directory, required_js_scripts wp_register_script('my_script', get_template_directory_uri() . '/js/my_script.js', array('jquery')); wp_enqueue_script('my_script'); } add_action( 'wp_enqueue_scripts', 'wp_add_scripts' );That’s Ravin’s example with the if removed, that’s all I changed.
Bob
Forum: Fixing WordPress
In reply to: Adding Javascript data table into my wordpress siteDo you mean that you pasted the “JavaScript” code into WP post?
————-Let’s start with basics:
For any web page – built with WP or not – to run JavaScript on a web page, the browser must be given the code to run and told when to run it.
You tell the browser the code by having a <script> </script> tag set in the html either with the the code between the tags or with the src= parameter of the <script> tag specifying what file the browser is to retrieve from server to get the code. That is, you tell the browser the location of the file containing the JavaScript.
Let’s assume the code is in the file name myjavascript.js in the same directory on the server as the file containing the page’s HTML.
In the <head> </head> section (best place to put such a tag) of the HTML, we code:
<script type="text/javascript" src="myjavascript"></script>That tells the browser to request that file from the server and that it contains JavaScript code.
Next – to tell the browser when to execute the code —
Let us further assume that myjavascript.js contains a function named myfunction.
To get the browser to execute that function, we have to tell it when to execute it.
A browser can execute JavaScript in many places – when the page is loaded, when a button is clicked, when a link is clicked, etc.
“Open” JavaScript code (code not within a function) is executed when the browser “sees” it in the page.
If we want the code to be executed when the page is loaded, we would code the <body> tag like:
<body onload="myfunction();">When the page finishing loading, myfuntion will be executed.
If we want the function to be executed when the visitor clicks a button, we would code:
<input type=”button” name=”buttonname” value=”textshownonbutton” onclick=”myfunction();”>
If we want to execute the function at a specific point in the page because it is going to create text or HTML that we want to be visible at that point in the page. We would code:
<script type="text/javascript> myfunction(); </script>If we are creating the entire web page ourselves, it is easy to put the necessary coding where it should be.
With WP things are a tad more complex and unfortunately, Raven’s reply is only half of what needs to be done to execute JavaScript on particular WP page, at a particular point on the page.
Here’s the URL of the documentation the wp_enqueue_scripts hook – https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts – like far too many documentation pages, it does not really tell you the full story – such as why you need to “enqueue” scripts and what happens when you do so.
When you “enqueue” a JavaScript with WP, you are first, telling it the name of the file so it can check to see if that file has been previously enqueued – to prevent possible conflict of the file names – and then it inserts, in the <head> (I believe) a script tag referencing that file, similar to the one I showed above:
<script type="text/javascript" src="myjavascript"></script>That will tell the browser where to find the JavaScript code.
Now you must tell WP where you want the JavaScript executed.
You could modify the appropriate theme file to include the <script> tag to execute the function but that means you have to check to see if your change is still there after the theme is updated for new versions.
A cleaner way to tell WP where to execute the function, is to make a shortcode for the function.
Here is the WP documentation page for shortcodes.As shortcode is something like [executeJavaScript] which you put in a post or page, using the WP editor, and it causes some PHP code to be executed. In fact, I’m going to write a [executeJavaScript] shortcode for you.
You should read the documentation on shortcodes but here is the shortcode I just wrote, that I think will do what you want to do, this is PHP code to be put in the theme’s functions.php file:
/***************** ShortCode to execute JavaScript in a post or page
The code to be executed is specified via the code= parameter.The code can be one or more lines of JavaScript, separated by semicolons.
[executeJavaScript code=’alert(“Hello”); alert(“Goodbye”);’]
If you simply want to execute a function:
[executeJavaScript code=’functionname();’]If you want to execute a function, that function should be contained in a .js file which
is properly “registered” and “enqueued” with the WP wp_enqueue_scripts hook.
Find the documenation on wordpress.org.Registering and enqueuing a .js file causes WP to include a <script> tag in the HTML for the page.
I’m not going to go into that here, look at the WP documenation for
the wp_register_script at
https://developer.wordpress.org/reference/functions/wp_register_script/
and the wp_enqueue_script at
https://developer.wordpress.org/reference/functions/wp_enqueue_script/If a function you specify is not found, you’ll get an error, in the browser console, such as
ReferenceError: functionname is not defined http://www.example.com/wpdr/ Line 185The line number will be the number of line in the WP created HTML for the post or page.
You are on your own as regards the correctness of the JavaScript, both syntax and execution
and any possible security issues.
**********************
function execute_my_javascript_shortcode( $arguments=”) {
// Did the user specify code to be executed, let’s check carefully to avoid any unneccessary warnings or errors.
// Is the argument null, or is it not an array, or is the key not there, or is the element null? – True anywhere causes the error message
if (($arguments === ”) || (is_array($arguments) === false) || (array_key_exists(‘code’, $arguments) === false) || ($arguments[‘code’] === ”)) {
// code was not specified, tell the user about it
echo ‘<b><big>!!! You did not specify the JavaScript code, on the [executeJavascript] shortcode, to be executed.
‘ .
‘You must specify the code to be executed like:
[executeJavaScript javascript=”code”]</big></b>‘;
}else { // code was passed
return ‘<script type=”text/javascript”> ‘ . $arguments[‘code’] . ‘</script>’; // echo out a script tag to execute the code
}
// NOTE – always “return” the shortcode “stuff” if you echo it, it will appear at the top of the post instead of where you want it}
add_shortcode( ‘executeJavaScript’, ‘execute_my_javascript_shortcode’ );
/************************ End of executeJavaScript shortcode coding **************************************/`I tested that and it worked for me. Let me know if you have a problem with it.
To execute your JavaScript – it should be in a function, named, for example, mytablejs in a .js file in the theme’s directory. Then you must enqueue and register it.
You of course use your own .js file name and function name —
Next, code:
[executeJavaScript code'mytablejs();']Where you want the table to appear in your posts.
Let me know if you have problems – show me the coding in the post and the exact messages you get.
Hopefully this all shows properly when I post it – fingers crossed.
Forum: Fixing WordPress
In reply to: Move wordpress to it's own directory – Redirect RuleI should have added:
If you can get the WP installation back to where it was before you moved it and it was working properly, install the Duplicator plugin and use it to move WP to the other directory.
It can be a tad contusing the first time you use it,let me know if there is anything you don’t understand before you that step or enter a particular value.
I highly recommend you use Duplicator to make backups of all WP installations before you make any changes – including move it – so that you have a way to go back to a stable situation.
I’ve been in Data Processing since 1973 and us ol’ timers won’t change anything without a backup – we learned, early on, and probably the hard way, that a backup can save your butt when you make a change and screw things up.
Backups are not some waste of time – backups can make the difference between a broken program, or web site, and one that works.
Knowing that you can go right back to where you started from gives you a profount sense of security.
All ways back things up before making any changes.
Also, make changes and test them somewhere other than on a “production” site. You can setup a sever/PHP/MySQL package on your own computer – too complicated to go into here – or you can simply create another directory on your hosting server and move WP to that directory before making changes. You then test the changes there and when you’ve got it working, you make the changes to the production system.
If you put no links, anywhere, to the test directory, it will be private and no one else can get to it. That makes it safe to test things out before implementing them on the production site.
When I say “If you put no links, anywhere,” – I also mean that you don’t give out a link to that directory to ANYONE – even on a forum like this. Once you give out a link you can almost count on it becoming more widely known.
I’ve had WP installations in “unknown” directories for months at a time and no one has ever found them.
Be wary if you want to post an error message from the test site, change the URL to hide the actual location.
Bob
Forum: Fixing WordPress
In reply to: Site CSS/JS not working remotelyJason,
I dug a bit more into the page as it is now delivered and it looks like the issue has change a bit, not sure but:
I see the theme’s css file being referenced as http://192.168.1.100/wp-content/themes/xylus/style.css?ver=1.5
Was that like that earlier?
Regardless, it is not accessible – I get connection timeouts regardless of how I go after it – clicking the entry in the page source (the source of the frame content) or copying the URL from the source and pasting it into the address bar of a new tab.
Why is that referencing a file at that IP, 192.168.1.100, when it should be references to files at http://broadtune.com.au/
I loaded http://180.181.153.86/ directly into my browser – that is the URL of the source of the frame on the page at http://broadtune.com.au/ – and looked at all of the links (hovered my cursor over them) and, except the one to wordpress.org, all of URLs contain the IP address: 192.168.1.100
Things are really screwed up.
————————————-
I think you need to backup and punt.Install Duplicator on your local WP – the one that works.
Use it to create a Package and “download” the package files to somewhere on your computer.
Save the entire contents of your “online” WP installation and empty the directory.
Put the Package files in the directory where you want WP to run on the “online” site and then got to installer.php
If you don’t fully understand the input it requests, ask me before you proceed, it can be a tad confusing the first time you use it.
[ Really, really discouraged and redacted ]
Forum: Fixing WordPress
In reply to: Move wordpress to it's own directory – Redirect RuleYou are going to have to give me more details of when and were you are encountering the 404 errors and exactly how you moved it.
Are you saying that you moved one blog and the other blog is now having problems?
You said
I chnaged WordPress in root folder url setting to http://www.mydomain.com/blog/. I move all files from root to blog folder. I created an index file in the root
I don’t know what you are referring to as the “root folder url” unless you you mean the “WordPress Address (URL)” or “Site Address (URL)” In the Admin Dashboard under Settings -> General
Before you changed anything, did you make a backup of the entire WP site you moved? Did you backup your database?
Always have a backup of both before you make any changes – large or small.
A backup is a way to undo changes which cause problems and get back to a known condition of the code and or database.
A simple way to make a backup is to use the Duplicator plugin. It was originall written to provide a way to move a WP installation (like you are doing) but it also is a quick way to make a backup of the entire site, including the database.
If you have a backup, it would be easiest to restore it and then use Duplicator to make the move you want.
If there is not backup, just give me as much detail as you can of each step you took in moving the WP installation, settings you changed and where and how you changed them, directories created, what new files did you create and where did you create them, etc.
Details as to the 404 errors – what sort of posts or pages are you trying to get to when you get a 404? Are you saying that the changes to one blog have caused problems on the other blog? etc. etc
You showed the following:
*/
define(‘WP_USE_THEMES’, true);/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . ‘/blog/wp-blog-header.php’ );Is that from wp-config.php? Is that code you changed? ??
Bob
Forum: Fixing WordPress
In reply to: Mobile Issuesthewineguy –
I just sent you an email via the contact email on your site.
Bob
Forum: Fixing WordPress
In reply to: Adding Javascript data table into my wordpress siteDoesn’t he need a change somewhere else to cause the script tag to be written to the page where he wants the table?
Bob
Forum: Fixing WordPress
In reply to: Keeping content area white, and background greyI’m curious –
which change fixed the problem – the one I suggested or the one that Donna Peplinskie suggested?
Bob
Forum: Fixing WordPress
In reply to: Keeping content area white, and background greyTry the following:
Ditch your added CSS:
body.page-id-373 { background-color: #FFF !important; background-image: none; }Add, at the bottom of the theme’s style.css file:
.white { background-color: white; }Upload the changed copy of the style.css file, and the one where you had your addsed CSS (if it was in a file other than that style.css file), to the server and then go look at the page again.
Is that what you want?
The <div> tag containing the text I think you want with a white background is coded as:
<div class="white">but there is no class rule named white defined, that I can find. So, the code I show, above, will add one.
Check other pages to see if this effects them.
Also – you have extraneous </p> tags on your page.
The first I noticed is on the line that defines the div I just showed you. The full line is:
<div class="white"><center></p>When I look at the source with Firefox, that tag is in red, that indicates an error or exception, and if I hover over it the message: “No p element in scope, but p end tag seen” is displayed. That means the browser could not find the <p> tag to match the </p> tag.
That is not a fatal error, but it is the type of error which can cause screwy formatting that usually is hard to pin down.
Bob
Forum: Fixing WordPress
In reply to: Keeping content area white, and background greyWell –
When you speicfy a background color for the body tag and specify !important (which means – “hey, everyone, ignore any backgroud color specifications on all tags that are subordiante to the body – that is, everything) you will get pages with white backgrounds.
It’s as simple as that.
Please be specific as to what “content area” you are referring to.
Are you referring to the “area” which has the text starting with:
A Nationally Recognized Expert
If you are looking for an advisor who is on the cutting-edge of the latest trends in investing and financial planning, you have come to the right place. While many advisors boast about keeping up-to-date on the latest academic research, Dr. Lach creates it. He has multiple publications in peer-reviewed academic journals and has been sourced as a subject…
If you want only that element to have a white background, you have to code the CSS for the white background at a level which will affect only the one element.
What theme are you using?
Also – you have the text in that area centered – it is proven fact that large blocks of centered text are harder to read and look worse than left justified text.
Bob
Forum: Fixing WordPress
In reply to: Yet another Page Not FoundI’m still not sure what I’m supposed to be seeing where..
Also that link http://test.unionbc/home returns server not found – should it be http://test.unionbc.org/home?
If I go to http://test.unionbc.org/home I see what I take to be your home page.
When I go to http://test.unionbc.org I get the 404, page not found error.
What should I see when I go to http://test.unionbc.org? Should I see your home page that is now at http://test.unionbc.org/home?
That is, should http://test.unionbc.org take me to your Home page?
Also – that bible verse in the header block on the Home page at http://test.unionbc.org/home is almost unreadable because it is is a dark font color against a very dark background. I’m not sure what control you have over that but it is almost invisible.
Bob
Forum: Fixing WordPress
In reply to: Site breaks after: if ( is_page( is eneteredSo the “break” is that the material shows up on all page instead of just one specific page – correct.
What specific page is is supposed to show on ?
I don’t have a copy of the functions.php file from the theme you are modifying and without it I can’t tell where the code should be put.
Also, Magazine Pro theme is a commercial theme and support for commercial themes is not supplied on these forums. Only free themes are supported here.
You must go to the seller’s support site or forum for assistance with their products. http://my.studiopress.com/themes/magazine/
Bob