How to stop subdirectory wordpress install adding head elemets to entire site?

I am working on a static website, www.example.com

and have installed wordpress in a subdirectory: www.example.com/blog.

I have created a custom elemnt on the home page which pulls in the latest blog. To do this I have included the following code:

<?php
require('blog/wp-blog-header.php');
get_header(); 
?>

The problem I am having is that this is pulling in the meta description as well as some other meta tags which are not needed, what is the best way to fix this?

FYI, this is the custom code which pulls in the latest blog:

<section class="homeBlog">
                <h2>Read Our Latest Blog</h2>
                <div class="homeBlogContainer">


                    <?php if (has_post_thumbnail()) : ?>
                        <?php
                        $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
                        ?>

                        <div class="tm-featured-image" style="background: url('<?php echo $image; ?>') #FFF no-repeat; background-size: cover;">
                            <a href="https://wordpress.stackexchange.com/questions/341318/<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
                            <img class="uk-invisible" src="<?php echo $image; ?>" alt="<?php echo $image_alt; ?>">
                            </a>
                        </div>

                    <?php endif; ?>

                    <div class="home-blog-text">
                            <?php $the_query = new WP_Query( 'posts_per_page=1' ); ?>                   
                            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> 
                            <div class="articleMeta">
                                <div class="profileImage">
                                    <?php echo get_avatar( get_the_author_meta( 'ID' ), 100 ); ?>
                                </div>

                                <div class="profileAuthor"> 
                                    <h3><a href="https://wordpress.stackexchange.com/questions/341318/<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
                                    <p class="profileMeta">
                                        <?php
                                            $date="<time datetime="".get_the_date('Y-m-d').'">'.get_the_date().'</time>';
                                            printf(__('%s <br> %s', 'warp'), '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'" title="'.get_the_author().'">'.get_the_author().'</a>', $date);
                                        ?>
                                        <?php edit_post_link(__('Edit', 'warp'), ' / <i class="uk-icon-pencil"></i> ',''); ?>
                                    </p>
                                </div>
                            </div>    


                            <?php the_excerpt(__('(more…)')); ?>    


                            <p class="btn">
                                <strong><a href="https://wordpress.stackexchange.com/questions/341318/<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">read more</a></strong>
                            </p>

                            <?php 
                            endwhile;
                            wp_reset_postdata();
                            ?>
                    </div>
                </div>
            </section>

1 Answer
1

This is because you call get_header() which already require your theme header.php, in which the meta tags are defined.

You should learn how to use get_header() in the WordPress Codex

To summarize:

  • You must rename your wp-blog-header.php file to header-blog.php and place it in your wordpress theme directory.

  • Then you can require it using this function : get_header('blog').

If your header is the same on everypage, you can just replace the header.php and call it with get_header().

Leave a Comment