The four-hyphens for block of code does not seem to work. So I am using the backtick so it won't look like I'm screaming. Anyway:
I want to add an image to the sidebar on the home page only. So probably I should do something like this in functions.php:
add_action( 'beans_sidebar_after_markup', 'add_home_image' );
function add_home_image() {
if ( is_home ) {
?>
<img src="...etc..." />
<?php
}
}
But I cannot find any sort of beans_sidebar_after_markup
function on your website, and I also cannot tell if it should be after
or prepend
or what. Or maybe it should be content_after
, but then how does my image get inserted into the correct place on the sidebar? (Which is also part of my question re this image.)
PS. I would find it very helpful if your code references showed at least one example of how the particular function is used.
Thanks again!!
Hey Wyn,
Beans hook are quite easy to use once you understand how it works. I suggest you take a look at this reply which explains how the hooks work (extracted from Beans Docs).
So if you want to add an image in your primary sidebar before the first widget only on your blog home, inspect the page sidebar and look at the markup ids, you will see that there is a beans_sidebar_primary
markup-id. Based on the explanation about the hooks the reply mentioned above, you would use the beans_sidebar_primary_prepend_markup
as follow:
add_action( 'beans_sidebar_primary_prepend_markup', 'example_home_sidebar_image' );
function example_home_sidebar_image() {
if ( is_home() ) {
?><img src="...etc..." /><?php
}
}
This apply to any markup which has a markup id on the page which makes it incredibly flexible.
Happy coding,
Hi Thierry,
Okay, just to clarify that I do understand this, the "hook" specifies where the new_function code gets "done" -- in other words, basically one uses these action hooks as follows:
add_action
( where = hook
, doing-what = a_new_function
) ;
And then one defines
function a_new_function ( ) {
what the function does }
Yes?
100% correct 😉