Cp1 Posted February 4, 2016 Share Posted February 4, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/300729-custom-plugin-only-working-in-admin-frontend-not-affected/ Share on other sites More sharing options...
maxxd Posted February 4, 2016 Share Posted February 4, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/300729-custom-plugin-only-working-in-admin-frontend-not-affected/#findComment-1530758 Share on other sites More sharing options...
QuickOldCar Posted February 4, 2016 Share Posted February 4, 2016 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'); Quote Link to comment https://forums.phpfreaks.com/topic/300729-custom-plugin-only-working-in-admin-frontend-not-affected/#findComment-1530764 Share on other sites More sharing options...
Cp1 Posted February 4, 2016 Author Share Posted February 4, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300729-custom-plugin-only-working-in-admin-frontend-not-affected/#findComment-1530766 Share on other sites More sharing options...
maxxd Posted February 4, 2016 Share Posted February 4, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/300729-custom-plugin-only-working-in-admin-frontend-not-affected/#findComment-1530769 Share on other sites More sharing options...
Cp1 Posted February 4, 2016 Author Share Posted February 4, 2016 (edited) 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 February 4, 2016 by Cp1 Quote Link to comment https://forums.phpfreaks.com/topic/300729-custom-plugin-only-working-in-admin-frontend-not-affected/#findComment-1530773 Share on other sites More sharing options...
maxxd Posted February 4, 2016 Share Posted February 4, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300729-custom-plugin-only-working-in-admin-frontend-not-affected/#findComment-1530782 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.