How To Apply HTML To Every WP Blog Post

13 replies
Hi,

I am using a plug-in called Quick Adsense to apply ads to every blog post on my WP blog.

At the moment, I only want to show the ads on a few of my posts so I want to apply a piece of shortcode (<!--NoAds-->) into the HTML of every blog post. and then manually remove that from the posts where I want the ads to appear.

How can I quickly and easily add the below piece of code to the very start of the HTML part of every single blog post?

<!--NoAds-->

I have over 1300 posts so doing it manually at this time is not an option.

James
#apply #blog #html #post
  • Profile picture of the author Nuke07
    Originally Posted by JamesPenn View Post

    Hi,

    I am using a plug-in called Quick Adsense to apply ads to every blog post on my WP blog.

    At the moment, I only want to show the ads on a few of my posts so I want to apply a piece of shortcode (<!--NoAds-->) into the HTML of every blog post. and then manually remove that from the posts where I want the ads to appear.

    How can I quickly and easily add the below piece of code to the very start of the HTML part of every single blog post?

    <!--NoAds-->

    I have over 1300 posts so doing it manually at this time is not an option.

    James
    As per my understanding to your problems...
    There're two cases:

    1). To add shortcode in wp posts
    2). To add shortcode in wp templates

    If you wanna add shortcode into wp posts then paste those shortcode into WP Post Visual Editor.

    Or

    If you wanna add shortcode into wp page templates then use following code:

    <?php echo do_shortcode('paste your shortcode here');?>
    {{ DiscussionBoard.errors[9513561].message }}
  • Profile picture of the author SteveJohnson
    Does the plugin obey the <!--NoAds--> HTML comment? Is that how it works?

    Doing what you want in one swoop will take doing a database query to insert the text at the top of the post_content field. It has to be done carefully though, and it's not something you'd do by hand. It should be in the form of a small plugin that will only run once.

    BE CERTAIN you have a good database backup before you undertake this, in case someone screws it up.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[9515041].message }}
  • Profile picture of the author zakclayton
    Hey, i presume the plugin will have a shortcode that you can use either in the body copy or within your templates.

    as above you'll want something like <?php echo do_shortcode('[quick_adsense]'); ?> in your index.php or post template.

    Reference: Function Reference/do shortcode « WordPress Codex
    Signature
    >>>> You can't beat free traffic! Check out my 5 Ultimate Free Traffic Sources <<<<
    {{ DiscussionBoard.errors[9515615].message }}
  • Profile picture of the author kewkii
    The code needs to be in the content not in the template so that it can be removed on a per post basis.
    {{ DiscussionBoard.errors[9516129].message }}
    • Profile picture of the author JamesPenn
      Originally Posted by kewkii View Post

      The code needs to be in the content not in the template so that it can be removed on a per post basis.
      Yes - that's exactly what I need to do? Any ideas?
      {{ DiscussionBoard.errors[9523343].message }}
  • Profile picture of the author RobinInTexas
    Originally Posted by JamesPenn View Post

    Hi,

    I am using a plug-in called Quick Adsense to apply ads to every blog post on my WP blog.

    At the moment, I only want to show the ads on a few of my posts so I want to apply a piece of shortcode (<!--NoAds-->) into the HTML of every blog post. and then manually remove that from the posts where I want the ads to appear.

    How can I quickly and easily add the below piece of code to the very start of the HTML part of every single blog post?

    <!--NoAds-->

    I have over 1300 posts so doing it manually at this time is not an option.

    James
    If you only want the ads on a few posts, it would be much easier to use a plugin that gives you the option to show the ad on individual posts using a shortcode. There are several that have that option. If your "quick adsense" doesn't, look for another that fits your situation.
    Signature

    Robin



    ...Even if you're on the right track, you'll get run over if you just set there.
    {{ DiscussionBoard.errors[9518820].message }}
    • Profile picture of the author JamesPenn
      Originally Posted by RobinInTexas View Post

      If you only want the ads on a few posts, it would be much easier to use a plugin that gives you the option to show the ad on individual posts using a shortcode. There are several that have that option. If your "quick adsense" doesn't, look for another that fits your situation.
      For now, I only want the ads on a few posts.

      I need to update the majority of my posts so that the pages comply with Google Adsense guidelines.

      But what I went to do is set the "rules" for where the ads go...

      For example...

      Show <!--Ads1--> after image 1
      Show <!--Ads2--> at the end of the post

      I can then apply this to ALL blog posts but then cancel it out by showing <!--NoAds--> on pages that are not ready for the ads.

      Then when I update the page I can remove the NoAds code and the ads will be shown exactly where I want them.

      Yes, I could just go into each post and manually add where I want Ads1 and Ads2 to go, but then when it comes to making wholesale changes to the ad positioning, I won't be able to do it.
      {{ DiscussionBoard.errors[9523352].message }}
  • Profile picture of the author rhinocl
    I think SteveJohnson gave you a good solution with doing a database query. I don't know why he's recommending you use a plugin rather than doing it manually, but he should know better than I do.I 'm guessing this is the type of plugin you could get written on fiverr for $15 or less.
    {{ DiscussionBoard.errors[9527248].message }}
  • Profile picture of the author yukon
    Banned
    Just past the HTML/Adsense code in the single.php theme file above the post php code. Done.
    Signature
    Hi
    {{ DiscussionBoard.errors[9527604].message }}
    • Profile picture of the author Dan Grossman
      Originally Posted by yukon View Post

      Just past the HTML/Adsense code in the single.php theme file above the post php code. Done.
      This is the right answer. You don't need plugins or database queries or anything else. Just paste the code into the right file(s) in your theme, which are what dictate the HTML of every page of your WordPress site. Everything else that's on every page (navigation bars, sidebars, etc) is coming from the theme -- so should your ads.

      Here's a guide to what files control what pages of your site:

      http://codex.wordpress.org/images/1/..._Hierarchy.png

      A few quick pointers: as Yukon said, single.php is the template for pages displaying a single post. In most themes, index.php is the template used for the homepage and often any other page that lists multiple posts. If the ad is supposed to be in the header or footer of the design, then header.php and footer.php are the files to paste the code into.
      Signature
      Improvely: Built to track, test and optimize your marketing.

      {{ DiscussionBoard.errors[9527624].message }}
      • Profile picture of the author kewkii
        Originally Posted by Dan Grossman View Post

        This is the right answer. You don't need plugins or database queries or anything else. Just paste the code into the right file(s) in your theme, which are what dictate the HTML of every page of your WordPress site. Everything else that's on every page (navigation bars, sidebars, etc) is coming from the theme -- so should your ads.

        Here's a guide to what files control what pages of your site:

        http://codex.wordpress.org/images/1/..._Hierarchy.png

        A few quick pointers: as Yukon said, single.php is the template for pages displaying a single post. In most themes, index.php is the template used for the homepage and often any other page that lists multiple posts. If the ad is supposed to be in the header or footer of the design, then header.php and footer.php are the files to paste the code into.
        But that will put the code on every post of the site, from what I understand the need is to add the code to all existing posts, then in the future once a posts have been 'ad readied' remove it.

        Originally Posted by JamesPenn View Post

        Yes - that's exactly what I need to do? Any ideas?
        I've a simple SQL script to append text to posts. I'm unwilling to post it here as I don't fully understand your requirements (plus I feel twitchy about posting SQL that will change the db - what works for one person might not work for another). With regards to inserting the ad shortcodes eg. after image 1 ... a little more tricky - in my mind it will need some php knocking up to parse the posts and find the appropriate insertion point.

        Message me if you want to talk further / have the script and the long list of caveats that will come with it
        {{ DiscussionBoard.errors[9528446].message }}
  • Profile picture of the author newgadget123
    Embeditpro is plugin which is used to apply the html to Every WP Blog Post.
    {{ DiscussionBoard.errors[9566944].message }}
  • Profile picture of the author gajdeva
    Nice Post

    Here’s how to add functioning HTML To Every WP Blog Post....
    {{ DiscussionBoard.errors[9585314].message }}

Trending Topics