Archived topic
Custom hook or alternative
15 replies · Started by Juan Ramón on February 19, 2022
Hello again friends,
This time it's not a problem, it's a question.
Would it be possible to create a hook to add a code (the Polylang switcher) just below the first image of each post?
I know it is possible to insert there with Ad Inserter, but I would like to try it with Elements to reduce Ad Inserter requests for a performance test.
Thanks
JR
Hi there,
if the image is in the post content, then no you cannot use a Element. Element only use action hooks, and what you need ( which is what Ad Sense is doing ) is using the_content filter hook.
Hi David,
Thanks
I suspected it, it was in case there was a possibility to find a way to put it at least below the featured image.
The end I have placed it with a hook in generate_after_entry_header to do the performance tests.
Regards
JR
Can i see a post on the site where you want to add this ?
Yes, David
Now is this Polylang switch code right aligned with CSS
*/-div class="div-right-/*
<?php pll_the_languages(array('show_flags'=>1,'hide_if_no_translation'=>1,'show_names'=>1,'hide_current'=>1)); ?>
*/-/div-/*
Hi Juan,
If you have a featured image on your post, and the featured image is set to below header, then you can use generate_after_entry_header, set the priority to 11.
Please refer to this visual hook guide: https://docs.generatepress.com/article/hooks-visual-guide/
Hi Ying,
Tnx.
Almost every post has the first image as a featured image. What I don't know if I can set -below header- to all images in bulk because the idea is to use the hook for all posts.
I'm still investigating.
The image seems added manually, you can make featured image to show automatically at customizer > layout > blog > featured image > posts, tick the Display featured images box.
Yes, I thought so, but the problem is that when it is not a different image it is shown twice and I don't think there is an easy solution (or I haven't found one).
You can remove the images added manually.
Sure, but it's not worth so much manual work (it would have to be automated) just to place a switcher, there are more than 5500 posts with images.
No problem, thank you very much for the effort, I'll leave it up while I do the tests and then I'll place it with Ad Inserter.
Thanks again
JR
Manually add featured image to the post is a lot of manual work to begin with, but since there're already 5500 posts, I guess it's too late to change that.
If you'd like we can use CSS to hide the first image from all posts.
It is appreciated, but I would have to check all posts so that there are no icons or other images before the first large (cartoon) image in each post.
Anyway, if you can pass me the CSS you propose, I can test it in staging to measure the amount of work that would be involved in revising the posts.
Give this CSS a try:
.post .entry-content >*:nth-child(2).wp-block-image {
display: none;
}
If the image block is the second block in the post, you don't need to modify the CSS. (your site info is erased, can't quite remember the image's position.
Change the number 2 to the image block's order within the post.
Hi Ying
Great, I'll save it for when I have time to try it in staging.
Good night
