I want to insert an ad code in the middle of a post via
I found several links but either they don't use
functions.php or don't insert the code in the middle.
Can anyone tell me how to do this?
Also, I don't want to use a plugin.
This function inserts your ad code after the specified paragraph.
Use the Short code API.
It's perfect for what you are trying to do.
There are several alternatives:
First, you can use shortcodes as @iambriansreed suggest, but you need to know PHP programming to register the shortcode. The following code is from a website (in spanish) that shows how to program a simple shortcode with Adsense:
Second, you can use a plugin like Quick Adsense to achieve the same shortcode but easily customizable or let the plugin select where to put the ads.
And finally, you can write your own code to add ads at n-th paragraph (i.e. exploiting each paragraph and selecting the n-th paragraph and add there your ads code). It's not the best solution but it will be fully customizable.