Title: variable google sidebar advert
Last modified: August 19, 2016

---

# variable google sidebar advert

 *  [taglad](https://wordpress.org/support/users/taglad/)
 * (@taglad)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/variable-google-sidebar-advert/)
 * I’m trying to make the sidebar advert on posts **fit** the content of the post.
   In other words, if the post is small, I might place one ad in the sidebar; or,
   if it’s a big post, I would place two ads in the sidebar.
 * Is there some way of doing this that’s …. umm… simple ?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [haochi](https://wordpress.org/support/users/haochi/)
 * (@haochi)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/variable-google-sidebar-advert/#post-732514)
 * It doesn’t seem like WordPress has such function out of the box that returns 
   the length of a post (number of characters or words).
 * You can use the [Post Word Count plugin](http://wordpress.org/extend/plugins/post-word-count/)
   to get the number of words per post, but you will have to modified the plugin
   first.
 * Open post-word-count.php, replace `echo number_format($totalcount);` with `return
   $totalcount;`
 * Install and activate the plugin.
 * Open your theme’s sidebar.php, add the following code to wherever you want to
   second ad to show up.
 *     ```
       <?php
       if(mdv_post_word_count(true) >= 100){ //replace 100 with the desire number of words.
       ?>
       YOUR AD CODE HERE
       <?
       }
       <?>
       ```
   
 *  Thread Starter [taglad](https://wordpress.org/support/users/taglad/)
 * (@taglad)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/variable-google-sidebar-advert/#post-732731)
 * Thanks for the suggestion Haochi, but I’ve solved it without using a plugin by
   using a Custom Field and evaluating that field within the post template.
 * In the post, I have a custom field called “sidebarpost”. If I think the post 
   is smaller or bigger than my default ad, I give a value to this.
 * In the template I use :
 * <?php $sidebarpost=get_post_meta($post->ID, ‘sidebarpost’, $single = true);
    
   if ($sidebarpost == “small”) { include(“sidebaradvertsmall.php”); } elseif ($
   sidebarpost == “button”) { include(“sidebaradvertbutton.php”); } elseif ($sidebarpost
   == “none”) { echo “”; } else {include(“sidebaradvertdefault.php”); } ?>

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘variable google sidebar advert’ is closed to new replies.

## Tags

 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)
 * [tweak](https://wordpress.org/support/topic-tag/tweak/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [taglad](https://wordpress.org/support/users/taglad/)
 * Last activity: [18 years, 2 months ago](https://wordpress.org/support/topic/variable-google-sidebar-advert/#post-732731)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
