Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1146965

    Hello,

    I would like to add a banner image to the area below the logo and menu, and above the page title/breadcrumb area. I would like it to be automatic, so that there is always this banner there whenever a new post is created (and for currently existing posts, too). Is there a way that I can make this happen? Thanks for any info you can provide!

    You can see what I’m looking for here

    Best regards,

    Luke

    #1147964

    Hey lukeskelly,

    Thank you for the inquiry.

    It is possible to insert additional content below the header using the “ava_after_main_container” hook. Just add the following snippet in the functions.php file.

    add_action('ava_after_main_container', function() {
       // add content here
    }, 10);
    

    You can also include conditional tags inside the hook in case you want to control where the content should be displayed.

    // https://codex.wordpress.org/Conditional_Tags?PHPSESSID=1adce0e8881abee402658ac2c7b31bd1

    Best regards,
    Ismael

    #1148728

    Thanks, Ismael! I’ve added the snippet to the functions.php file of my child theme and whenever I do that it breaks the site. The site shows a “This site is experiencing technical difficulties” error. When I remove that snippet from the php file, the site is ok again. Any ideas?

    Additionally, if I wanted to add an image, how would I do that in the php syntax? Does it take html? Is it like

    add_action('ava_after_main_container', function() {
       // <img src="abc.jpg" />
    }, 10);

    Also, if I apply this to my functions.php can I be sure that this image I’m trying to add below the logo and menu only shows up on blog posts and pages, and not the homepage (since there’s already a masthead image there)?

    Best regards,
    Luke

    • This reply was modified 5 years, 2 months ago by lukeskelly.
    #1149142

    Hi,

    Thank you for the update.

    The following snippet should work. It will add a container below the header. Of course, you can include more content if necessary.

    add_action('ava_after_main_container', function() {
       $output = "<div class='below-header'>This is a content below the header.</div>";
       echo $output;
    }, 10);
    

    You can then use the following css to style the container.

    .below-header {
       display: block;
       width: 100%;
       height: 100px;
       background: red;
    }
    

    Best regards,
    Ismael

    #1152577

    Hi Ismael,

    I tried your revised code above in my functions.php file and I’m still getting the “The site is experiencing technical difficulties.” error.

    Luke

    #1152751

    Hi Luke,

    Can you please check server log for error?

    Here is how to find it:http://snapcreek.com/blog/wordpress-error-log-friend/

    Best regards,
    Victoria

    #1157971

    Hi Victoria! See private content for log file error.

    #1158763

    Hi,

    Sorry about that. We used double instead of single quotes in the class attribute within the output variable. We edited it accordingly. Please copy the snippet directly from the forum. It should work properly now.

    Best regards,
    Ismael

    #1159308

    That worked! However, is there a way to add this to only the post pages? That is to say, not on the homepage or any other page on the site. Just the post pages. We want to do this because when you click on a post (https://www.internationalcomplianceblog.com/u-s-hits-cuba-with-another-round-of-sanctions-de-minimis-threshold-dropped-to-10-percent/) you can’t see that it is for the International Compliance blog.

    Thanks again for your help so far.

    #1159749

    Hi,

    Thank you for the update.

    However, is there a way to add this to only the post pages?

    Yes, that is possible. We can add a conditional tag before declaring the $output variable so that the function will only be executed on single post pages. Add this code..

    if(!is_single()) return;
    

    .. above this line:

    $output = "<div class='below-header'>This is a content below the header.</div>";
    

    Best regards,
    Ismael

    #1160467

    Perfect! That worked. Thanks!!!!!

    #1160515

    Hi,

    I’m glad this was resolved. If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Add banner to blog post pages’ is closed to new replies.