Tagged: Blog, Shortcodes
-
AuthorPosts
-
July 13, 2018 at 8:00 pm #985296
Hi,
I’d like to use the blog posts module on a homepage, and add a shortcode to show something just below the “read more” button. Where do I best add the code for this?
Thanks in advance!
July 15, 2018 at 8:25 pm #985735Hey elvirais,
You can add this code to the child theme functions.php:
add_filter( 'post-format-standard', 'avia_read_more_filter', 10, 1 ); add_filter( 'post-format-gallery', 'avia_read_more_filter', 10, 1 ); add_filter( 'post-format-video', 'avia_read_more_filter', 10, 1 ); add_filter( 'post-format-image', 'avia_read_more_filter', 10, 1 ); add_filter( 'post-format-link', 'avia_read_more_filter', 10, 1 ); add_filter( 'post-format-quote', 'avia_read_more_filter', 10, 1 ); add_filter( 'post-format-audio', 'avia_read_more_filter', 10, 1 ); function avia_read_more_filter($current_post) { if(!is_singular()) { $current_post .= do_shortcode('[MYSHORTCODE value="1" value2="2"]'); } return $current_post; }
and replace [MYSHORTCODE value=”1″ value2=”2″] with your shortcode. Make sure the parameters of the shortcode are wrapped into “” quotes.
Best regards,
DudeJuly 15, 2018 at 10:06 pm #985765I tried this, to add the [jetpack-related-posts] shortcode:
[...] $current_post .= "[jetpack-related-posts]";
but the entire post didn’t display.
July 17, 2018 at 12:10 am #986158I tried again and even with this simple test code it doesn’t work:
function avia_read_more_filter($current_post) { if(!is_singular()) { $current_post .= "<p>TEST</p>"; } return $current_post; }
July 18, 2018 at 10:37 am #986869Hi elvirais,
Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?
Best regards,
VictoriaJuly 18, 2018 at 10:43 am #986872Hi,
In the end I solved it a different way, I created a small plugin that did what I needed:
//Hooks a function to a filter action, 'the_content' being the action, 'hello_world' the function. add_filter('the_content','hello_world'); //Callback function function hello_world($content) [...]
This way I could add what I wanted at the end of a single post and/or just after the read more button.
July 18, 2018 at 3:28 pm #987044Hi elvirais,
Glad you got it working for you and thank you for sharing! :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.