Take the 2-minute tour ×

I have a blog on wordpress and I need to center an object. What is the easiest way?

share|improve this question
You want CSS, not PHP. –  drudge Feb 9 '11 at 0:41

4 Answers 4

up vote 0 down vote accepted

You would actually use HTML and CSS to do that. :)

<div style="text-align: center;"> YOUR OBJECT HERE </div>
share|improve this answer

You don't center objects using PHP. You position them using CSS. Read this for further info.

share|improve this answer

You cannot do layout with PHP, it is for programming logic. To do layout you use CSS and HTML. To center text you can use the text-align tag that jdhartley showed above. To center a block like a table or div you use the following CSS:

.centered {width:950px; margin-left:auto; margin-right:auto;}

<div class="centered">Bunch of stuff to be centered</div>

The width can be anything, but you do have to set it. It can be a percent like 90% or a pixel width.

share|improve this answer

PHP is just a scripting language that performs data manipulation and such. You process that information and output HTML (usually.) Something you can do is just close the PHP and drop some HTML into it like this:

<?php //PHP stuff ?>
<p style="text-align:center;">HTML Stuff</p>

alternatively you can do it all in PHP like:

$output = '<p style="text-align:center;">HTML Stuff</p>
echo $output;
share|improve this answer

Your Answer


