• Any thoughts why my attempt to make a shortcode in my template functions.php file won’t work properly:

    https://wordpress.pastebin.com/m783592d1

    if I use the custom shortcode [pagelinks] any forced echos (echo “the id is”) will show at the top of the post no matter where the shortcode is pasted.

    also, $post->ID is NULL. this suggests the function is running before the loop is run… i think

    Any thoughts would be appreciated.

    Basically, I am wanting to create a shortcode [pagelinks] that my client can use to have a special stylized list of the links to all the children of that page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • if I use the custom shortcode [pagelinks] any forced echos (echo “the id is”) will show at the top of the post no matter where the shortcode is pasted.

    Probably just a formatting issue. Some HTML/CSS should straighten that out.

    also, $post->ID is NULL. this suggests the function is running before the loop is run… i think

    No. You just don’t have access to the $post variable from within your specialLinks() function. Put global $post; at the top of the function.

    Thread Starter bdiddymc

    (@bdiddymc)

    Thanks apljdi,

    Seems the global $post was the big issue.

    Also, seems if I “echo” something it is returned at the top of the_content() when the shortcode is used. If I “return” it, then it works as desired… Not entirely sure why that is. Would be interested to know why that is.

    Cheers

    Also, seems if I “echo” something it is returned at the top of the_content() when the shortcode is used.

    Because you are echoing raw text out of context, so to speak. That is not encased in the <p> tags or <div> tags that would normally help control its placement. So the text sort of floats around and finds a convenient spot.

    I used “return” instead of echo and now my content no longer shows up…

    disregard, i put the strings into variables and returned it that way, works fine.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Fairly straight forward shortcode… i thought’ is closed to new replies.