Skip to content

What's the best way to do this (echo php/html)?

So in the Wordpress functions.php I have a function that inserts a copyright into the footer. What's the best way to echo this? Warning: PHP noob.

 <?php echo date('Y'); ?> <a href="<?php echo home_url(); ?>/" title="<?php bloginfo('name'); ?>" rel="home"><?php bloginfo('name'); ?> </a>

Here's the function so far.

add_action('wp_footer', 'st_footer');
do_action('st_footer');
function st_footer() {
	//loads sidebar-footer.php
	get_sidebar( 'footer' );
	// prints site credits
	echo '<div id="credits">';
}

}

0 points4 comments
Open on Reddit
About this post
Posted
Archived
Score
0 · 100% up
Kind
Text
ID
sqlgx

Author

43
posts
141
comments
0
media
View profile

4 comments

...and this is exactly why so many programmers have a problem with wordpress. It's such an unmitigated mess.

3 points

I'm not sure what you're trying to do, but if you just want a © 1901 - 2012 type thing, this should work...

<?php 
    echo '&copy; 1901 - ' . date(Y); 
?>

You would replace 1901 with whatever year you started your blog or website, and the date(Y) puts in the current year so it's always up to date.

There are more advanced things you can do that check to see if the decades are the same (so you can do 2010-12) and stuff like that, but that's the most basic easiest one I can think of.

2 points

Sorry, I probably wasn't that clear. The thing I'm really having trouble with is the href mixed with the php/home_url. Basically going from html to php and back to html.

1 points

The only variable you actually need is the date('Y')

The other things like home_url() and bloginfo('name') are always the same. So you can actually hardcode them. I'm assuming you'll be using it on only one website and you're not distributing theme around for other persons to use.

2 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.