Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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

1 Answer 1

up vote 1 down vote accepted

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]
share|improve this answer
    
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
    
Worked! Thank you! –  Jacob Oct 4 '13 at 17:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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