I think this might be an easier question but I can't figure it out.

How can I add simple text inside a short code?

For example:

$return_string .= '<a href="'.get_permalink().'"><div>'.read more.'</div></a>';

So, I don't just want to return text, but I want to return text and a link. I am using this shortcode to query the posts, but I want to add a "read more" link after each excerpt, but I cant figure out how to just add the text "read more."

Any help would be appreciated!

  • Do you want to create a shortcode with the above output? – birgire Oct 4 '13 at 17:34
  • possible duplicate of Highlighting Sub topic in a post? – s_ha_dum Oct 4 '13 at 17:37
  • I checked out the other topic and I don't think it is the same, but perhaps I am wrong....I will be a little more accurate in my post – Jacob Oct 4 '13 at 17:39

hello you can try this

// Add Shortcode
function text_shortcode( $atts , $content = null ) {
  // Code
  return '<div>' . $content . '</div>';
add_shortcode( 'b', 'text_shortcode' );

The shortcode will be something like this

[b] content [/b]
  • Won't I need to define $content somewhere? would it look like this: $content = 'read more'? – Jacob Oct 4 '13 at 17:43
  • you will pass it in the shortcode, for example in the post you will have [b]this is the content[/b] ... if it's null then in the function you can assign a default value. $content = something. – pl4g4 Oct 4 '13 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.