Forums

How to add a permalink code (6 posts)

  1. jmorin
    Member
    Posted 3 years ago #

    How can I add the dynamic permalink in the post itself? Is there some escape character that's needed?

    EXAMPLE: In my post for, say, tomorrow, I want to add something like:

    MARY LINKS TO %this_permalink% EVERY DAY.

    and have it automatically populate the PHP code. I don't mean in the template footer or other php pages. I want to add it to the text (or HTML) body of the post itself. Thanks! Jeff M

  2. SteveSmith1983
    Member
    Posted 3 years ago #

    You could use this plugin
    http://wordpress.org/extend/plugins/exec-php
    to put the template tag within your post.

  3. Dagon Design
    Member
    Posted 3 years ago #

    I did not test this, but it should work :)

    <?php
    /*
    Plugin Name: Add Permalink
    Plugin URI: http://www.dagondesign.com
    Description: Replaces %this_permalink% with the permalink of the post/page being viewed
    Author: Dagon Design
    Version: 1.0
    Author URI: http://www.dagondesign.com
    */
    
    function add_permalinks($content) {
    	return str_replace("%this_permalink%", '<a href="' . get_permalink() . '">' . get_permalink() . '</a>', $content);
    }
    add_filter('the_content', 'add_permalinks');
    ?>
  4. SteveSmith1983
    Member
    Posted 3 years ago #

    That's really easy! I had no idea. I'm going to be using that for a few things from now on I think - thank you :).

  5. Dagon Design
    Member
    Posted 3 years ago #

    No problem :)

  6. geekygrrrl
    Member
    Posted 3 years ago #

    I came across this post and am so thankful I found it! Exactly what I was looking for as well! Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags