Jump to content
Cp1

Custom plugin only working in admin. Frontend not affected

Recommended Posts

I'm new to Wordpress and am working on creating a couple plugins in my spare time. I've started some work but only see my plugins working in the admin. No matter what I do the frontend of my website is not affected. Caching is disabled on my browser on the MAMP server, I am working locally. I also know it isn't a cache issue because my changes show up immediately in the admin. Any ideas or suggestions?

Share this post


Link to post
Share on other sites

Are you applying the plugin anywhere? It's hard to tell what's going on with the information you've given us - what's the plugin supposed to do? Does it use shortcode to create output? Is it a custom post type? Are you using the correct WordPress hook?

Share this post


Link to post
Share on other sites

As maxxd stated need to see your code.

 

About the hooks, are you adding the action to both admin area and then another the location you desire within the frontend?

add_action()

 

add_action('admin_menu', 'admin_menu_function');

add_action('wp_head', 'show_something_in_header_function');

add_action('the_content', 'show_something_in_content_function');

Share this post


Link to post
Share on other sites
global $wp_version;

die($wp_version);


I've watched a couple tutorials and followed step by step. I'm trying to add some javascript to the page. I need it on the frontend. I only see it in admin.

 

I've watched another tutorial and try to step it back from what I was doing. Above is what I've done. I decided to see if any code will work just in case the hooks I was using were wrong.

 

It shows the version in the admin. It seems no matter what I do, I could drop a bomb on the site. Nothing, that I have done affects the frontend, but shows up in admin.

Share this post


Link to post
Share on other sites

Honestly, it shouldn't show up in admin, either. What hook are you using in your functions sheet? If you're trying to add javascript you need to use the wp_enqueue_script hook. You can find more information and a couple examples here.

 

What's the full code you've written, including the plugin functions file?

Share this post


Link to post
Share on other sites

My code is on my home computer so I don't have access to it until tonight. It does have the PHP tags and a simple header.

 

I've had this problem for about a week or so. I had to not work on it for a few days because it is so frustrating. I have tried watching several tutorials and have deleted and reinstalled everything being careful at every step. I have stepped back and created a few simple plugins going step by step with the tutorials that I am watching. Everything seems fine. I activate the plugin like normal, and then nothing changes on the frontend, only admin.

 

I've ruled out browser cache, php cache, server cache. I have disabled all other plugins just in case they might be doing something. Is there some simple setting or something I'm missing? The code I use seems to work for everyone else.

 

The site I am working on is a live site. I copied the code and database to my local machine. In wp-config.php I have updated the database information and set the MAMP path the the folder containing the code. I had to update the following below to stop the admin from redirecting to the live site:

 

define('WP_HOME', "");

define('WP_SITEURL',"");

 

I'm all out of ideas. I will post my code for the simple plugin printing the version. I have not done much else because I cannot get past this problems.

 

Any guesses or suggestions would be appreciated.

Edited by Cp1

Share this post


Link to post
Share on other sites

As long as you're not actively developing on a live site, you're good.

 

What your plugin is doing right now is just flat-out printing the value of $wp_version. It's not actually doing anything, so where it's doing it isn't really all that important at the moment. The file where you put the WP plugin headers is your basic functions sheet - here you'll use WP action and filter hooks to let your plugin know what to do and when. So, if you're attempting to include some JavaScript you'd do something like the following:

function myPluginQueueScripts(){
	wp_enqueue_script('myPlugin', dirname(plugin_dir_url(__FILE__)).'/js/myPluginScript.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'myPluginQueueScripts');

The links  I posted in my last reply will give more information on the wp_enqueue_script() function and the wp_enqueue_scripts action hook.

 

WordPress has some ... strange behavior at times, and it has a million ways of doing some things. It's huge, a bit frustrating, and kind of a mess once you start poking around under the hood; so don't get frustrated (easier said than done, I realize), just keep Googling. There's a ton of resources on the web - some are good, some are not, and you'll have to use your judgement and some time to figure out which is which. That being said, you can always ask here.

Share this post


Link to post
Share on other sites

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.