WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] My First Shortcode Function (3 posts)

  1. martcol
    Member
    Posted 1 year ago #

    add_shortcode('rose' , function(){
    	return '
    	<div class="authorchoice">
    	<h3>Get in Touch</h3>
    	<p>This was written by Rose and you can contact her <a href="URL_to_mysite.co.uk/contact/?1mailto_id=2">here</a>.</p>';
    });

    So, that's my first real bit of coding since starting out with WordPress a few years ago. All that it does is give each author on the site a link to the contact page with their email selected as the person to contact.

    What I think I would prefer is for the function to know who wrote the page or post the shortcode is used in and go from there or maybe, for there to be one function that makes each choice depending on an attribute selected like, [authorchoice name=rose]

    Would that be possible/difficult and if it's not too hard to do, could someone just give me a couple of clues where to start?

    Thanks

    Martin

  2. Bas Schuiling
    Member
    Posted 1 year ago #

    You can use the author functions for that. If you want to display extra stuff like email address you can simply use 'the_author_meta' or similar to query the information you want to display.

  3. martcol
    Member
    Posted 1 year ago #

    Thank you

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.