Jump to content
#StayAtHome ×


This topic is now archived and is closed to further replies.


Wordpress Plugin Shortcode

Recommended Posts

Hey folks,


Sorry if this is in the wrong section. I have posted on Wordpress but there doesn't seem to be much support there.


I am new to Wordpress Plugin development and have created a simple plugin for practice purposes.

The plugin allows to display Google Adsense anywhere in a post or page by using [vicads]

However, I am unable to get the shortcode working for pub-xxxx


Here is the php code where I am having issues:


/* Create the tags to use */
function google_pub() {
return '<div align="center">
<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 type="text/javascript"

add_shortcode('vicads', 'google_pub');

/* Runs when plugin is activated */

/* 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 */

//*************** 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>


In the Plugin Options page, I have a form set that would allow the user to just put in their pub ID.

It works fine if I put my own pub ID directly into the code above. The ads show fine. But when I use:




It doesn't work.


Can anyone give me any suggestions or hints on what I should be putting there?

Share this post

Link to post
Share on other sites

  • 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.