I know this going to be very easy question for people with good PHP knowledge.

I have a WordPress website self hosted. I designed it for mobile devices and I would like to install Millennial Media advertisements in it. Millennial Media does not really provide detailed instructions and web resources strangely are not available!

I have knowledge in HTML,CSS and JavaScript but very poor in PHP :( . any way I can do some changes PHP to achieve what I want, but I can't write them from zero and integrate them by my self.

Ok long story short This the code provided by Millennial Media:

/* Millennial Media PHP Ad Coding, v.7.4.20                     */ 
/* Copyright Millennial Media, Inc. 2006                        */ 
/*                                                              */ 
/* The following code requires PHP >= 4.3.0 and                 */ 
/* allow_url_fopen 1 set in php.ini file.                       */ 
/*                                                              */ 
/* NOTE:                                                        */ 
/* It is recommended that you lower the default_socket_timeout  */ 
/* value in the php.ini file to 5 seconds.                      */ 
/* This will prevent network connectivity from affecting        */ 
/* page loading.                                                */ 

/*------- Publisher Specific Section -------*/ 
$mm_placementid = 123456; 
$mm_adserver = "ads.mp.mydas.mobi"; 

/* The default response will be echo'd on the page     */
/* if no Ad is returned, so any valid WML/XHTML string */
/* is acceptable.                                      */
$mm_default_response = "";


/*----------- BEGIN AD INITIALIZATION ----------*/
$mm_id = "NONE";
$mm_ua = "NONE";
@$mm_ip = $_SERVER['REMOTE_ADDR'];

if (isset($_SERVER['HTTP_USER_AGENT'] )){
     $mm_ua = $_SERVER['HTTP_USER_AGENT'];

if (isset($_SERVER['HTTP_X_UP_SUBNO'])) {
          $mm_id = $_SERVER['HTTP_X_UP_SUBNO'];
} elseif (isset($_SERVER['HTTP_XID'])) {
          $mm_id = $_SERVER['HTTP_XID'];
} elseif (isset($_SERVER['HTTP_CLIENTID'])) {
          $mm_id = $_SERVER['HTTP_CLIENTID'];
} else {
          $mm_id = $_SERVER['REMOTE_ADDR'];

$mm_url = "http://$mm_adserver/getAd.php5?apid=$mm_placementid&auid="
          . urlencode($mm_id) . "&uip=" . urlencode($mm_ip) . "&ua="
          . urlencode($mm_ua);
/*------------ END AD INITIALIZATION -----------*/

/* Place this code block where you want the ad to appear */
/*------- Reusable Ad Call -------*/
@$mm_response = file_get_contents($mm_url);
echo $mm_response != FALSE ? $mm_response : $mm_default_response;
/*--------- End Ad Call ----------*/

I want the Advertisement to appear in the footer area ( I will edit the footer.php in twenty eleven theme ) but I want to know where shall I put these pieces of codes in wordpress files or shall I create a new ones and what to name them?

would some please help me with this issue and provide me with the file's names that required to be edited and how would they look like in the end ?


  • What about the answer you received at StackOverflow? – brasofilo Jan 25 '13 at 9:01
  • Was incomplete and doesn't fullfill my need. I tried to delete it from stackoverflow , but i couldn't. Question here make more sense. – Jamal Jan 25 '13 at 9:05
  • Did you try it? What didn't work? – brasofilo Jan 25 '13 at 9:09
  • 1
    Just as was answered over there: in theory, this code should work if pasted as is. Did you try loading this very PHP file alone? Without WordPress? What about the notes and requirements in the first lines? Does your server meet them? ::: What you ask and what you receive are not necessarily the same thing, this is people helping people for free, remember? – brasofilo Jan 25 '13 at 9:24
  • 1
    I see you failed to comment on the answer at stack overflow, if you don't indicate the answer is insufficient, the person can never know that s/he needs to improve it. I'm inclined to say the SO question is a more appropriate place, as this requires no WordPress knowledge to do, only PHP knowledge – Tom J Nowell Jan 25 '13 at 11:31

I would not put that code into the theme. Create a plugin with the following content:

/* Plugin Name: Millennial Media Ads */

add_action( 'show_ads', 'mma_show_ads' );

function mma_show_ads()
    # copy your PHP code into this function.

In your theme choose the place where you want to show the ads and write:

do_action( 'show_ads' );

That’s all. The benefit is: If the ads don’t work some day, or the ad server was hijacked or whatever, you can just deactivate the plugin and all is fine.

  • What about the php.ini the i have on the server is php5.ini and it has one line of coding.. How would i edit it and I add thevrequired parameters , because after the coding I end up with text of links .. Thank u mr toscho – Jamal Jan 25 '13 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.