WordPress.org

Ready to get started?Download WordPress

Forums

Get Recent Posts with shortcode (3 posts)

  1. swayam.tejwani
    Member
    Posted 1 year ago #

    Hello All,

    I am trying to display latest posts using wp_get_recent_posts function, in one of the post i have used a shortcode [newsletter] but instead of diaplying the content of shortcode, this itself is got printed [newsletter] my code is this
    `$args = array(
    'numberposts' => 2,
    );

    $recent_posts = wp_get_recent_posts($args);

    foreach( $recent_posts as $recent ){

    echo '<li><span class="header"><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a></span> '. $recent['post_content'].'</li> ';

    }`
    Please Help me out

  2. JulienRobitaille
    Member
    Posted 1 year ago #

    Hi swayam.tejwani,

    I think that the shortcode [newsletter] is wrapped into an html element. In order to fix this, you need edit your post, then go in the text tab on top right of the content editor. If the shortcode [newsletter] is wrapped into any html element ( like div or p) remove that element and update your post.

    I hope this help,

    Julien

  3. swayam.tejwani
    Member
    Posted 1 year ago #

    Hello Julien,

    In the editor i have only shortcode [newsletter] and nothing else, for more info i am pasting here my code of shortcode
    [code]
    function nl_form(){
    ?>
    <h4>Newsletter</h4>
    <?php //echo DB_NAME(); ?>
    <p>Vestibulum sit amet tincidunt sit amet, tincidunt at dolor. </p>
    <form action="javascript:void(0)" method="get" id="nl_formid" onsubmit="return callajax();">
    <input required placeholder="Your Email" class="email" type="text" name="emailname" id="email_id" title="keyword" />
    <input type="submit" name="Subscribe" value=" Subscribe " alt="Subscribe" id="subscribe_btn" title=" Subscribe " class="subscribe_btn" />
    <span class="email_validate" style="display:none;">Enter Valid Email Address</span>
    <img id="loadingimage" style="display:none; float: right;position: relative; left: 36px;top: 20px;" src="<?php echo plugins_url('images/ajax_loading.gif',__FILE__); ?>">
    <div class="cleaner"></div>
    </form>
    <?php
    }
    add_shortcode('newsletter','nl_form');
    [/code]

Topic Closed

This topic has been closed to new replies.

About this Topic