Chris J. Popp
Chris J. Popp

Reputation: 25

Formatting get_the_date items within Wordpress

I know I can change the color and size of the date within a single entry page via css that's already in place but how can I format the individual items within the get_the_date call?

Right now if I use ('j M. Y') I will get "26 Nov. 2014" on one line. I want to be able to have this display as:

26

Nov. 2014

As you can see, the date is on a line by itself and is larger than the Mon. Year line.

The page that I am editing is template_tags.php and the line that I am editing is

esc_html( get_the_date('j M. Y') )

Any help is appreciated.

Upvotes: 0

Views: 8921

Answers (4)

harjinder singh
harjinder singh

Reputation: 71

<?php echo esc_html(get_the_date( 'j' )); ?>&nbsp;<br />
<?php echo esc_html(get_the_date("M. Y")); ?>

Upvotes: 0

Chris J. Popp
Chris J. Popp

Reputation: 25

Wound up doing:

'<div align="center" style="display:block"><span id="da1">&nbsp;'. esc_html( get_the_date( 'j' ) ). '</span><br><span style="font-size:10px;display:block;">'.esc_html( get_the_date( 'M. Y' ) ) . '</span>')

No echo needed

Thanks everyone!

Upvotes: 0

diggy
diggy

Reputation: 6828

You can use the template tag twice:

echo '<span class="date_1">' . esc_html( get_the_date( 'j' ) ) . '</span>';
echo '<span class="date_2">' . esc_html( get_the_date( 'M. Y' ) ) . '</span>';

Upvotes: 2

rnevius
rnevius

Reputation: 27102

Break it up into different items. For example:

echo '<div class="day">' . esc_html( get_the_date("j") ) . '</div>';
echo '<div class="month-year">' . esc_html( get_the_date("M. Y") ) . '</div>';

You can then target each of these <div>s via their CSS class names.

Upvotes: 2

Related Questions