• I would like to add blog feed into my WordPress static page(Show last 3 posts in a div). Since wordpress doesn’t execute php code inside posts/pages, I want to do it using shortcode.

    I have created feed.php file which contains

    <?php
    
    function getblogposts() {
    
    wp_get_archives( array( 'type' => 'postbypost', 'limit' => 3, 'format' => 'html' ) );
    
    }
    ?>

    And added code blow to functions.php: (using child theme)

    <?php
    include(WP_CONTENT_DIR . '/feed.php';
    add_shortcode( 'getblog', 'getblogposts' );
    ?>

    And unfortunately, when I input [getblog] into the site, it displays as raw [getblog].

    Any idea what I’m doing wrong?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WordPress shortcode php issue’ is closed to new replies.