WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Shortcode to link to a tag archive page (11 posts)

  1. Bibhuti Bhushan Barman
    Member
    Posted 1 year ago #

    I don't know the way but i strongly need this.
    Actually my blog post have to keyword and i linked the keyword to tag archive page. But for this I have to add tag page link manually, I want a shortcode for post page to directly linkback to tag archive page in keyword. for example If i write [Something] or [tag]Something[/tag] or [Tag=Something] the something text will auto linked to the Something tag archive page like Something.

    I have searched lot on google and wp support pages but could't find the solution, If you anybody have the script or plugin then please share the process.

    Thanks in advance.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    I think the following will do what you want:

    add_shortcode('taglink','mam_tag_link');
    function mam_tag_link($atts,$content) {
       // Usage: [taglink]target[/taglink]
       // Generates a link to http://url/tag/target
       $url = home_url('/');
       $link ="<a href='{$url}tag/$content'>$content</a>";
    
       return $link;
    }
  3. Bibhuti Bhushan Barman
    Member
    Posted 1 year ago #

    Yeh! I just wanting this code. Thank you very much.

  4. Bibhuti Bhushan Barman
    Member
    Posted 1 year ago #

    A problem.
    This catching just the text what i type (ie- if i type [taglink]something[/taglink] it work but if i type [taglink]Something[/taglink] it not working because then link shows http://url/tag/Something that mean Capital letters is the problem and if i give a space also there is the same problem).

    If you have resourced about this then you may know the problem's solution if it possible please tell me.

    Thanks..

  5. vtxyzzy
    Member
    Posted 1 year ago #

    Sorry, I should have checked for that. Please try this:

    add_shortcode('taglink','mam_tag_link');
    function mam_tag_link($atts,$content) {
       // Usage: [taglink]linktext[/taglink]
       // Generates a link like <a href="http://url/tag/linktext">linktext</a>
       $url = home_url('/');
       $target = sanitize_title_with_dashes($content);
       $link ="<a href='{$url}tag/$target'>$content</a>";
    
       return $link;
    }
  6. Bibhuti Bhushan Barman
    Member
    Posted 1 year ago #

    Now Just Ideal.
    Thanks a lot.

  7. Bibhuti Bhushan Barman
    Member
    Posted 1 year ago #

    Everythonh ok but a question.
    Is there any way to add a shortcut in TiniMCE post editor?

  8. vtxyzzy
    Member
    Posted 1 year ago #

    Please explain more what you want. If you want to enter a shortcode, just type it into the text of the post.

  9. Bibhuti Bhushan Barman
    Member
    Posted 1 year ago #

    Ok. I want a shortcode on TiniMCE, means in the TiniMCE there will show a button for the link to tag function and if i select any text and then click the button, the select texts will auto get functioned like [taglink]select text[/taglink].

  10. vtxyzzy
    Member
    Posted 1 year ago #

    That will require writing a plugin, probably with some javascript code to make the changes. Here is a Codex article that may help: http://codex.wordpress.org/TinyMCE_Custom_Buttons

  11. Bibhuti Bhushan Barman
    Member
    Posted 1 year ago #

    ok..I will read this and If get solved the issue I will post the things here.

Topic Closed

This topic has been closed to new replies.

About this Topic