0

How to create a shortcode out of a PHP function?

My code looks like this:

function related_links_shortcode() {
      echo do_shortcode("<?php wp_related_posts()?>");
 }
add_shortcode('relatedlinks', 'related_links_shortcode');

My code only shows [relatedlinks] on my post

1 Answer 1

1

Using the do_shortcode() function actually calls another shortcode if that one exists. Instead, it should look like the following:

add_shortcode('relatedlinks', 'related_links_shortcode');
function related_links_shortcode() {
    return wp_related_posts();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.