This function inserts your ad code after the specified paragraph.
add_filter('the_content', 'wpse_ad_content');
function wpse_ad_content($content)
{
if (!is_single()) return $content;
$paragraphAfter = 2; //Enter number of paragraphs to display ad after.
$content = explode("</p>", $content);
$new_content="";
for ($i = 0; $i < count($content); $i++) {
if ($i == $paragraphAfter) {
$new_content.= '<div style="width: 300px; height: 250px; padding: 6px 6px 6px 0; float: left; margin-left: 0; margin-right: 18px;">';
$new_content.= '//Enter your ad code here....';
$new_content.= '</div>';
}
$new_content.= $content[$i] . "</p>";
}
return $new_content;
}
Related Posts:
- Difference between the_content() and get_post()?
- get_the_excerpt() not returning anything when post has no excerpt
- Function to wrap the_content in a div
- Function to show only first instance of shortcode
- Automatically insert php function into post $the_content
- Searching for content post
- str_replace function in theme
- Adding HTML to the end of every post with the Block Editor
- Inserting a functions output after the content
- Add caption functionality to custom WordPress theme
- Removing permalink from post thumb in twentyeleven
- Add Element as a Filter to the_content
- Insert template-part inside the content
- Remove links from the_content when using filters wp_trim_excerpt
- How do I pull excerpts from pages?
- does wp function the_content(); accept another tag inside
- Undefined variable error in new function
- How to remove a specific word at the beginning of the content and add it to the end of the content
- The_content and Preg_replace in loaded Iframe [closed]
- first paragraph of the_content as meta description
- Changing where my author box is printed
- Insert Content Before div#main from the functions.php File
- If is_single in functions.php
- Conditional function for excluding first image from content, not working
- Strip all HTML tags from product content and resave
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- $content is empty while using DOMDocument
- Shortcode to eliminate and replace with
- Function the_content
- How accomplish modification the_content if home/start page?
- Creating mixture of shortcodes to use in the visual/text editor
- How I can show short content with short tag
- Ajax call always returns 0
- plugins_url vs plugin_dir_url
- Where and how to put inline js in pages
- Get recent posts with thumbnail
- Overriding core functions in child theme
- how to create shortcode in wordpress
- Function returns different value when called from ‘save_post’ than when called on page load
- Displaying a random user with a shortcode
- Assign category using custom field?
- Should I ask a theme developer to use locate_template rather than require_once
- Customized wp_new_user_notification
- Updating users_can_register option?
- How to add an anonymous function in wordpress hooks by removing create_function
- Changing post category from dropdown
- How to update feed only 2-3 times a week (for Feedburner email)?
- Fatal error when trying to get admin email on contact form
- Is it good practice to use wpdb->query() function?
- img width and height attributes being set by get_the_post_thumbnail
- How to properly add NPM packages and integrate them in WordPress?
- wp_enqueue_script add integrity parameter
- change in form-checkout.php by using code in functions.php
- Custom function in My Custom Functions returning 403
- Register vendor JS/CSS only on pages that require them?
- Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function now working
- functions.php How to add css/js depending on Template Name?
- Why is my page feed returning empty content?
- Add other social networks to TwentyNineteen_SVG_Icons class in child theme?
- Including a specific Javascript Script in a template. Is my code correct?
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- Accessing two databases wordpress
- Add a jQuery Function
- append to existing parent theme function
- How do I change a parent theme’s function through the child theme?
- Enqueue script on every page except one
- Best way to handle lack of titles in microblogging
- Dropline menus — seperators between children only?
- Echoing function into WordPress NextGen gallery
- Redirect to other page if login
- get_terms (or tax_query) for term of current post?
- 404 when enqueue_script using plugin_url
- WP Customizer API loaded into functions.php
- How to use get_posts() function in functions.php
- the_widget() inside functions.php
- How Can I add a menu to the theme from withen the function.php file
- WordPress – using sessions?
- Trigger email alert if file downloaded
- Completely Disable WordPress RSS Feeds
- How to hide content on mobile in the functions.php file – woocommerce
- Load templates, pass arguments, and render output from functions.php
- WordPress Lite/Light
- Selecting specific query for offset
- Is_Page doesnt detect my page
- Show image after X para – center aligned
- Problems adding a new field to product in cart
- Function for Sticky Post on Categories causes issues with 404 behavior
- function replace_text for entire page
- Get value of pre-populated Gravity forms field as variable in my function
- Changing the color of post title [closed]
- Create html from function
- WP supersize not displaying when different languages flags are selected
- wp_list_pages change of children and anchor of parent
- Admin Panel errors because of functions.php
- WordPress not performing direct update
- Using Output from one Function and calling it into another
- How to add a class and title attribute to the link generated by next/previous post
- “Headers already sent” while trying to add a CSS file to my login page?
- Notice: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ in ….functions.php on line 73
- woocommerce_sort_product_tabs() expects an array