Tagged: ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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!

    #985735

    Hey 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,
    Dude

    #985765

    I tried this, to add the [jetpack-related-posts] shortcode:

    [...]
    $current_post .= "[jetpack-related-posts]";

    but the entire post didn’t display.

    #986158

    I 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;
    }
    #986869

    Hi 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,
    Victoria

    #986872

    Hi,

    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.

    #987044

    Hi 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

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.