Can't Get Custom Shortcode To Work
-
Hi folks,
I am new to WordPress Plugin development and at the moment, I am trying to create my first plugin, just for practice. I have everything done, but the shortcode doesn’t seem to want to work.
When I place [vicads] in a post, it should show a google banner ad. But it just shows [vicads] as text.
Here is my pluin php file:
<?php /* Plugin Name: VicAds Plugin URI: https://www.vicdesigns.com.au/wp/ Description: Display ads on any part of your posts or pages with a simple tag like: [vicads]Ad Code[/vicads] There are many plugins out there like this but not with as many features. Version: 1.0.0 Author: Dan O'Riordan Author URI: https://www.vicdesigns.com.au License: GPL3 */ /* Copyright 2011 Dan O'Riordan (email : [email protected]) This program is free software; you can redistribute it under the terms of the GNU General Public License version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /* Create the tags to use */ function google_code() { return '<script type="text/javascript"><!-- google_ad_client = "ca-$google_pub"; /* 468x60, created 7/23/09 */ google_ad_slot = "7951440521"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } add_shortcode('vicads', 'google_pub'); /* Runs when plugin is activated */ register_activation_hook(__FILE__,'vicads_install'); /* Runs on plugin deactivation*/ register_deactivation_hook( __FILE__, 'vicads_remove' ); function vicads_install() { /* Creates new database field */ add_option("google_pub", '$google_pub', '', 'yes'); } function vicads_remove() { /* Deletes the database field */ delete_option('google_pub'); } //*************** Admin function *************** add_action('admin_menu', 'vicads_menu'); function vicads_menu() { add_options_page('VicAds Options', 'VicAds', 'manage_options', 'vicads', 'vicads_options'); } function vicads_options() { if (!current_user_can('manage_options')) { wp_die( __('You are not allowed to view this page!') ); } ?> <div class="wrap"> <div id="icon-tools" class="icon32"></div> <h2>VicAds Options</h2> <p>Okay, as you know this is a very simple plugin that allows you to display Google Ads in your WordPress posts and pages with ease by simply using a small tag.</p> <form method="post" action="options.php"> <?php wp_nonce_field('update-options'); ?> <table class="form-table"> <tr valign="top"> <th scope="row">Google Pub:</th> <td><input type="text" size="40" name="google_pub" value="<?php echo get_option('', 'google_pub'); ?>" /></td> </tr> </table> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="<?php echo get_option('', 'google_pub'); ?>" /> <p class="submit"> <input class="button-secondary" type="submit" name="Save" value="<?php _e('Update VicAds'); ?>" id="submitbutton" /> </p> </form> </div> <div align="center">Place the following tag anywhere in your posts or pages to display the ads:<br /><br /><strong>[vicads]</strong></div> <?php } ?>
As you can see, I have an options menu setup where I would just put my google pub and the plan is to have the ads displayed in posts. I am unsure as to what I need to put into google_ad_client = “ca-pub-xxxx”;
Any help with this would be really appreciated.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Can't Get Custom Shortcode To Work’ is closed to new replies.