Using PHP to control Wordpress Content Display


There are lot of webmasters that still do not know how to customize the display of Word press pages or post. By doing this, you can prevent boilerplate repetition which can increase % similarity of the pages resulting in duplicate content. Say you have this piece of text in all pages and post sidebar (Using WordPress Arras Theme):

			<li class="widgetcontainer clearfix">
				<h5 class="widgettitle"><?php _e('Welcome to Arras Theme!', 'arras') ?></h5>
				<div class="widgetcontent">
				<div class="textwidget">
					<p>Arras Theme is a WordPress theme designed for news or review sites with lots of customisable features</p>
				</div>
				</div>
			</li>

The repetitive text that appears in all pages and post (including archives) is this: “Arras Theme is a WordPress theme designed for news or review sites with lots of customisable features.”

What is you only want to display that text on the homepage?. According to WordPress conditionals:WordPress Conditional Tags, you can use this tags to command the display of WordPress post/pages and archives. So in the sidebar.php template of wordpress. The above code can be revised to:

			<li class="widgetcontainer clearfix">
				<h5 class="widgettitle"><?php _e('Welcome to Arras Theme!', 'arras') ?></h5>
				<div class="widgetcontent">
				<div class="textwidget">
                                <?php
                                if (is_front_page()) {
                                echo "<p>Arras Theme is a WordPress theme designed for news or review sites with lots of customisable features.</p>";
                                }
                                ?>
				</div>
				</div>
			</li>

This is just a very basic example to show how PHP can be used by amateur and novice developers to control the display of content in WordPress post, pages and archives.



Related posts: