Forums

Adding posts as permalinks to other sites (3 posts)

  1. rex0810
    Member
    Posted 1 year ago #

    I am trying to adjust my theme to allow all posts categorized as "news" to automatically send users to the link specified in the body copy.

    the site I am working on is LHNow.com -- How do I write a function/hook that will allow the posts in the left column to point straight to the link? It currently adds the lhnow.com domain in front of it, as well as <p> tags.

    thanks!

  2. Anders
    Member
    Posted 9 months ago #

    I am not sure if I am understanding your question - are you trying to systematically replace all links within the body content of certain posts?

    If so, I would apply a filter to the_content. Something like:

    add_filter('the_content', 'my_function');
    
    function my_function($content) {
     global $post;
    
     //** Some code to figure if the post below to the news category or just return $content
    
     //** regex function replace all links with a prefix followed by the link
    
     return $content;
    
    }

    Obviously that example is incomplete, but maybe it'll get you on the right track. The most difficult part (in my experience) will be getting the right regular expression query, once you have it, just use preg_replace()

  3. Anders
    Member
    Posted 9 months ago #

    Oh, and you have the use the global $post variable since the_content filter doesn't pass the post object.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags