free hit counters
If you are using Internet Explorer as your browser please be running at least IE 7 or above. This site does not support IE 6 or below. Go here for the latest free version including easy download and installation instructions If you want to make it real easy on yourself, download Firefox , the most popular browser in the world. It's free and simple. You'll be so glad you did.
Jan
14
2009

Make an image show up on only one page

In your custom_functions.php file add this code. You can put it anywhere you want but I recommend putting it at the top after the <?php tag. Always describe the function and put it between the comment tags /*  */ at the beginning shown below in green. The comments aren’t shown on your rendered page and it just makes things easier for you to remember…

/*this function makes an image show up on only one page*/
function name of your function() {
if (is_front_page() ) {
echo ‘<div id=”box1″>
Insert your html, php, or javascript stuff here….
</div>’ ;
}}
add_action (’thesis_hook_before_content’ , ‘name of your function);

Note the following…

Name your function whatever you want

The if statement means that whatever follows after it will only show up on the front page

Hook it wherever you want

Use the hook map for a reference

Leaving a comment with code in it...

If you would like to leave a comment and you have examples of code you want to show, you must "escape the code". This allows the entire code to show correctly by inserting certain variable around certain tags to make them show. If you don't "escape the code" your code will show up broken, mangled, and it won't be able to be seen correctly. "Escaping the code" is very simple...

  1. Copy your code you want to show
  2. Click here to go to the site to escape the code
  3. Follow the directions, it's so easy
  4. Once you have the escaped code copied, paste it in the comments area where you want
  5. Now you can enjoy life


Go ahead, leave a comment...

{ 13 comments… read them below or add one }

KazClark March 25, 2009 at 9:52 am

So great to find this; I have been searching for just this pack of code as have tried all sorts of things to get a specific image on particular pages. The problem I am having is that the image shows up on all pages. How should I reference a page that is not front page; I can’t find this anywhere. For example, I have a page called maman-musings, which is my blog. Should that be:
if (is_maman_-_musings() ) or if )is_maman-musings())

Is it a page reference error or code mishap!

The code I have been using and tinkering with is this:

function blog_head_image() {
if is_maman-musings_page() {
echo ‘
}
}

Once I have the right code/ structure I can fire away a load of stuff I want to do. But I just seem to be missing the point and getting images on all pages plus code. If you can help me I would be so grateful; not had luck via other avenues.

THANKS!

Reply

KazClark March 25, 2009 at 9:53 am

Sorry, this is the full code I am using:

function blog_head_image() {
if is_maman-musings_page() {
echo ‘
}
}

Reply

Nasty March 25, 2009 at 12:09 pm

The “if” statement needs to be fixed. In your URL the name of your page is usually after your blog name. So go to the page in the blog you want to use and look at the URL…

Example: http://www.yourblog.com/maman-musings

Make sure you have the correct name of the page

Then, in your function the “if” statement should look like this…

if (is_page('maman-musings')) {
echo ' your stuff here '
}

Make sure you have the single quotes around the page name in the function

if you’re using some html code without and echo statement you need to stop the php engine temporarily so you would do this…

if (is_page('maman-musings')) { ?>
your html stuff here
< ?
}

Hope this helps, let me know how it works out for you...

Reply

Kaz March 26, 2009 at 11:53 am

Unfortunately not! I know this is my lack of understanding and not knowing/ understanding enough. I put my “stuff” in both formats as not quite sure if calling the image is html or not. Both ways I got image on every page and the code. I have left it up so you can take a look; if you are willing to be that generous with your time. I am so frustrated as once I get the structure of this code right I can do all I have left to do but I just can’t seem to get it! No doubt you will see a fault in my code but I have played with the lines/ tried different tweaks as on the DIY Forum and clearly I am missing something and my incompetence being highlighted every time I click through to site with fingers crossed. Thanks again! I’d like to think answer will be helpful to more than just me!

Reply

Nasty March 26, 2009 at 12:31 pm

Did you place the function with a hook to have the image show up? If you can, let me see your entire code for the function.

Reply

Kaz March 26, 2009 at 5:01 pm

function insert_bloghead()
if (is_page(’maman-musings’)) { ?>
echo ‘ <img class=”aligncenter” ‘ src=”http://www.mamanmedoc.com/wp-content/themes/thesis/custom/images/mamanblog.jpg” alt=”mamanbloghead” < ?
}

Should I be embarrassed?

Reply

Kaz March 26, 2009 at 5:03 pm

ps. I am using openhook and wondering if I should just go back to custom functions as I seem to be getting v confused knowing what to put in and what to leave out of openhook!
I owe you a book/ bottle of wine/ you should have a donate button!

Reply

Nasty March 26, 2009 at 6:39 pm

Never be embarrassed to ask questions! It’s how I learned everything. You have to start somewhere right?

Ok, you’re missing a few brackets and single quotes…

The whole function should look like this….

function insert_bloghead() {
if (is_page(’maman-musings’))
echo ‘< img class=”aligncenter” src=”http://www.mamanmedoc.com/wp-content/themes/thesis/custom/images/mamanblog.jpg” alt=”mamanbloghead”> ' ;
}

Note: the opening bracket after the function name, you had a single quote in the middle of your echo statement, you needed a single quote after the echo statement, the semicolon after the echo statement.

My mistake earlier, if you have an echo statement, you can keep the php running. You don't have to turn it off. Sorry about the confusion.

Paste that code into your openhook, make sure you check the little box that says "execute php in this hook"

Let me know how that works...

Reply

Kaz March 27, 2009 at 6:54 am

Hmmm – have tried all these, including above –

function insert_bloghead() {
if (is_page(’maman-musings’))
echo ‘’
}

function insert_bloghead()
if (is_page(’maman-musings’)) {
echo ‘’
}

function insert_bloghead()
if (is_page(’460′)) {
echo ‘’
}

function insert_bloghead() {
if (is_page(’maman-musings’))
echo ‘’;
}

function insert_bloghead() {
if (is_page(’maman-musings’))
echo ‘ ‘ ;
}

Nothing – am wondering if because this is blog page I need to add something else. I’ll repost on forum too – a mystery! THANKS again.

Reply

Kaz March 27, 2009 at 7:13 am

Have given up on openhook and tried this in custom functions:

function insert_bloghead() {
if (is_page(’maman-musings’)) {
echo ” ;
}
}

add_action(’thesis_hook_before_content_box’,'insert_bloghead’);

No code but no image either!

Reply

Nasty March 27, 2009 at 4:27 pm

For some reason your code is getting cut off in the comments. One mistake I see is the hook should be ‘thesis_hook_before_content’ not content_box. Try this code

function insert_bloghead() {
if (is_page(’maman-musings’))
echo ‘< img class=”aligncenter” src=”http://www.mamanmedoc.com/wp-content/themes/thesis/custom/images/mamanblog.jpg” alt=”mamanbloghead”> ‘ ;
}
add_action(’thesis_hook_before_content’, ‘insert_bloghead’);

Check out the hook map in the “your tool box” to see where you can place all the hooks

Oh, and I have to ask…when you added the code to your custom_fucntions.php file, did you save it and upload it to the correct place on your server?

Try this and let me know. We’ll figure it out!

Reply

Kaz March 28, 2009 at 3:51 am

Hi, tried it – no code showing up and site works; but no image. Am wondering if related to this being my blog page. I will try by referencing page number.
Yeah, right place as that’s how my nav bar and header other way around. I seem to be able to manage FTP ok; just this image causing me confusion! Different time zone to you so will let you know if I crack it!

Reply

Nasty March 30, 2009 at 6:47 pm

This was an email I received. Great Job!

GOT IT! Was blog reference issue.

function bloghead() {
if (is_home() && !is_front_page()){
echo ‘< div style="text-align:center;"><img src="
path to my image"
alt="mamanbloghead"/>';
} }
add_action('thesis_hook_before_content','bloghead');

Reply

Leave a Comment

Previous post: Insert custom links above header

Next post: Rotating random text on every post or page