-
AuthorPosts
-
October 10, 2019 at 10:03 pm #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
October 15, 2019 at 6:38 am #1147964Hey 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,
IsmaelOctober 17, 2019 at 12:53 am #1148728Thanks, 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.
October 18, 2019 at 7:26 am #1149142Hi,
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,
IsmaelOctober 31, 2019 at 12:38 am #1152577Hi 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
October 31, 2019 at 3:29 pm #1152751Hi 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,
VictoriaNovember 18, 2019 at 10:57 pm #1157971Hi Victoria! See private content for log file error.
November 21, 2019 at 9:57 am #1158763Hi,
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,
IsmaelNovember 22, 2019 at 7:38 pm #1159308That 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.
November 25, 2019 at 3:48 am #1159749Hi,
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,
IsmaelNovember 26, 2019 at 10:13 pm #1160467Perfect! That worked. Thanks!!!!!
November 27, 2019 at 1:43 am #1160515Hi,
I’m glad this was resolved. If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Add banner to blog post pages’ is closed to new replies.