I am trying to incorporate a number of small pieces of php code into a Wordpress database (for banner ads). Unfortunately the template I am using is not designed to take php code but rather html or javascript.

I wondered if there is a way to amend the template file to output the php.

The php code I am storing in the database as stream_ad468 is

<?php if(function_exists('drawAdsPlace')) 
  drawAdsPlace(array('id' => 1), true); ?>

The following file checks for the conditions, assigns the code to $ad468 and then ultimately tries to display the ad

<?php 
    if ( is_singular() ) {
        global $wp_query;
        $postid = $wp_query->post->ID;
        $ad468 = get_post_meta($postid, 'ad468_post', true);
        if ( !$ad468 && get_option('stream_ad468') == 'yes' ) {
            $ad468 = get_option('stream_ad468_code');
        }
    }
    if ( !is_singular() && get_option('stream_ad468') == 'yes' ) {
        $ad468 = get_option('stream_ad468_code');
    }
    if ( $ad468 ) {
?>
<div class="banner468">

    <?php echo stripslashes($ad468); ?>

</div>
<?php } ?>

If I directly replace

<?php echo stripslashes($ad468); ?>

with

<?php if(function_exists('drawAdsPlace')) 
  drawAdsPlace(array('id' => 1), true); ?>

the ad is displayed correctly but what I need to do (as there as similar files for other banner positions) is try and amend the line

 <?php echo stripslashes($ad468); ?>

so that it runs

<?php if(function_exists('drawAdsPlace')) 
  drawAdsPlace(array('id' => 1), true); ?>

I would point out that whilst the routine at the moment works perfectly with html or javascript code I have no need to keep this as all my banners are via a plugin which is using this php to call the ads.

Any help greatly appreciated.

Regards
Mark

<?php
if ( is_singular() ) {
global $wp_query;
$postid = $wp_query->post->ID;
$ad468 = get_post_meta($postid, 'ad468_post', true);
if ( !$ad468 && get_option('stream_ad468') == 'yes' ) {
$ad468 = get_option('stream_ad468_code');
}
}
if ( !is_singular() && get_option('stream_ad468') == 'yes' ) {
$ad468 = get_option('stream_ad468_code');
}
if ( $ad468 ) {
?>
<div class="banner468">
<?php echo stripslashes($ad468); ?>
</div>
<?php } ?>

Why not just leave that code as is and change the code assigned to $ad468?

<?php 
    if(function_exists('drawAdsPlace')) {
        //get drawAdsPlace() to return the code, not print it out
        $ad468 = drawAdsPlace(array('id' => 1), true);
    }else{
        if(is_singular()) {
            global $wp_query;
            $postid = $wp_query->post->ID;
            $ad468 = get_post_meta($postid, 'ad468_post', true);
            if ( !$ad468 && get_option('stream_ad468') == 'yes' ) {
                $ad468 = get_option('stream_ad468_code');
            }
        }
        if ( !is_singular() && get_option('stream_ad468') == 'yes' ) {
            $ad468 = get_option('stream_ad468_code');
        }
    }
    if ( $ad468 ) {
?>
<div class="banner468">
    <?php echo stripslashes($ad468); ?>
</div>
<?php } ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.