Jump to content

Installing Live Wordpress Site on Localhost


Cp1

Recommended Posts

Ok, I've been having a hard time writing a plugin and getting it to work. I've posted here and have gotten some very good advice. Every time I try to implement it it doesn't work. I think I may have found the problem, or at least have a clue. It may be how I installed it on my localhost.

 

I decided to dedicate most of the day to get something going on the site. I finally opened open the web console in Firefox after noticing one of the plugins installed on the live site wasn't working. What I noticed is when the live site loads it loads a bunch of content from the wp-content folder and the wp-includes folder. My local site loads only basic files. Both have the same plugins installed, with the settings the same. This explains why none of my plugin javascript, or anything for that matter was showing up.

 

Now, what am I doing wrong. I compressed the files using the tar command on my terminal. I used scp to transfer it to my computer. I tar to uncompress the file. I then set the "document root" setting on my MAMP server to the folder containing these files. I re-did these steps and got the same result.

 

I did notice the live site is www.sitename.com. My localhost is localhost/folder/Welcome.html. I reviewed the settings on my localhost and they seem to be the same as the live site.

 

Any suggestions. Is my document root wrong? I think once I get this figured out I'll be set.

Link to comment
Share on other sites

If I understand what you're asking, it sounds like you have an issue with including custom plugins you created -or- you're downloading other peoples plugins and they're not working...

 

A) If they're other people plugins, you're activating the plugins after you download them, correct?

 

B) If you made custom plugins, are you saving your custom plugins under the /wp-content/plugins folder? Are you including the header information on your plugins so wordpress knows where to find your plugin...like this:

<?php

/*

* Plugin Name: xyz plugin

* Author: Barak Obama

* Description: My first plugin

*/

 

Once you have the correct header information on your custom plugin, you still have to activate it. Go to your plugins menu, and click activate underneath the plugin name.

C) WP has a peculiar way of handling javascript and css. If you don't want to deal with the code, you can always use some plugins that are meant just for editing your css or using shortcodes to insert your javascript. For the coding purist, it's all about the hooks and where the files are located. If you have a custom plugin, wp has a lot of custom hooks to make adding your js/css easier. Here's an example of how to include a javascript file:

 

Let's say you have the following file and folder structure:

/wp-content/plugins/your-plugin/

my-plugin.php (this is your primary file where your plugin header info listed above would go)

/js/
my_script.js

 

You need to use a wordpress function called wp_enqueue_scripts() that imports your javascript so it appears on your main page. What you do is 'queue' your scripts - it's similar to 'include' or 'require' with php. You'll soon discover the wordpress codex is your best friend: http://codex.wordpress.org where all of these things like wp_enqueue_scripts() are detailed. 

 

First things first, we need an action hook to tell wordpress where to look for the functions:

 

add_action('admin_enqueue_scripts', 'your_js_function'); // if you want to make the scripts available to admins only
add_action('wp_enqueue_scripts', 'your_js_function'); // if you want your scripts available on the viewer side
 
Next, we setup the function from the above add_action call, not the lack of the 's' on the 'wp_enqueue_script' - it's because it's a different function than the one we mentioned above:
 
function(your_js_function) { 
 wp_enqueue_script('script name', (plugins_url('/js/my_script.js',__FILE__)));
}
 
So here, the function 'your_js_function' is referenced by both of the add_action calls above. The wp_enqueue_script function calls the name of your js file. From there you see where the file is located. The plugins_url function gives wp the path to your plugin directory - in this case it's the 'your-plugin' folder we referenced earlier. From here, we insert the full path from the plugin base directory to your js file. __FILE__ is basically a way of referencing the current page. 
 
 
 
To test and make sure you JS is included in your homepage - go to the admin panel (if you used admin_enqueue_scripts) or your home page (if you used wp_enqueue_scripts), open the page source, and in the head of the page, you should see you JS file referenced. 

Hope this helps :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.