• How to echo AdSense code with PHP? Here is the sample of my code which I am working for a wordpress plugin.

    <div class='mydiv'><?php echo stripslashes($adsensecode)?></div>

    All I want to insert adsense code inside a div with PHP. I also tried with htmlentities along with stripslashes but ad in not getting displayed.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You should echo the code directly.
    If you want to escape user input in the html, you must use the htmlspecialchars php function on the adsense id for example, but not for the full code bacause it contains special characters.

    Thread Starter Shrinivas

    (@shrinitech)

    Thank you for your reply byankov.. May I have the example code please? I have given the text area in my plugin option page where users can add their adsense code.. I want to display that ad in a wordpress blog post.

    I have given the text area in my plugin option page where users can add their adsense code.

    what plugin?

    I want to display that ad in a wordpress blog post.

    do you have php code enabled in the post content, for example via a plugin?

    have you considered to add the code via a filter for 'the_content'?

    have you considered to create a shortcode for the adsense code?

    Thread Starter Shrinivas

    (@shrinitech)

    Dear alchymyth,

    I am creating a new plugin, added a textarea in the option page of my plugin so that users can add their adsense ad code, everything is ready, plugin receives the saved adsense code in a variable $adsensecode, finally I am using jQuery to display the same adsense advertisement inside <article>, here is the part of the code-

    jQuery("article p:eq(1)").before("<div class='mydiv'><?php echo($adsensecode); ?></div>");

    but adsense advertisement is not getting displayed. If I write some lorem ipsum text in option page, it displays but the adsense code is not outputting the advertisement.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to echo adsense code in a div with PHP?’ is closed to new replies.