How can I add a header/footer/banners to all posts?

I would like to add a header, a footer and also banners to every post. The content should be the same for all and updated with modifications. How can this be done?

  • Ash
    • WordPress Hacker

    Hello @Decura

    I hope you are well today and thanks for asking the question.

    To add header, footer and banner in every post you can use following code in your functions.php or mu-plugins.

    add_filter('the_content', 'update_content');
    function update_content($content) {
    	if(!is_single()) return;
    	global $post;
    	if(get_post_type( $post->ID ) == 'post') {
    		$x = "<h1>This is header text</h1>";
    		$y = '<h3>This is a banner image</h3>';
    		$z = '<h5>This is a footer text</h5>';
    		$ad = '<h1>This is advertise text</h1>';
    		$paragraphAfter = 2;
    		$content = explode ( "</p>", $content );
    		$new_content = '';
    		for ( $i = 0; $i < count ( $content ); $i++ ) {
                        if ( $i == $paragraphAfter ) {
    			$new_content .= $ad;
    			$new_content .= $content[$i] . "</p>";
    		$new_content = $x . $y . $new_content . $z;
    	return $new_content;

    Above code will also add an advertise place in the middle of the content. If you don't want that you can remove.

    Please feel free to ask if you have more questions.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.