Adrian D'Urso
Adrian D'Urso

Reputation: 273

Centering an object in WordPress

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

Upvotes: 2

Views: 33079

Answers (6)

Raham
Raham

Reputation: 133

In Wordpress version 5.0 and above that use Gutenberg block system you may use the below code to achieve a centered blocked paragraph:

<!-- wp:paragraph {"align":"center"} -->
    <p class="has-text-align-center">Place your content here.</p>
<!-- /wp:paragraph -->

I've checked and the code will work without the <p class="has-text-align-center"></p>. In other words. This will work too:

<!-- wp:paragraph {"align":"center"} -->
Place your content here.
<!-- /wp:paragraph -->

As you may recognized already, you can change the {"align":"center"} to align your paragraph differently.

Upvotes: 0

Antonio Dimitrovski
Antonio Dimitrovski

Reputation: 31

Definitely easiest and the best way to centre whatever you want in WordPress is to use:

<center>whatever you need, a, img etc..</center>

Upvotes: 2

Steve Massing
Steve Massing

Reputation: 1893

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:

<style>
.centered {width:950px; margin-left:auto; margin-right:auto;}
</style>

<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.

Upvotes: 4

Aaron Hathaway
Aaron Hathaway

Reputation: 4315

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:

<?php
$output = '<p style="text-align:center;">HTML Stuff</p>
echo $output;
?>

Upvotes: 0

Demian Brecht
Demian Brecht

Reputation: 21378

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

Upvotes: 1

jdhartley
jdhartley

Reputation: 486

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

<div style="text-align: center;"> YOUR OBJECT HERE </div>

Upvotes: 3

Related Questions