• Resolved jokr

    (@jokr)


    Hi all,

    In a plugin I would like to add a custom feed. I have done this as follows:

    add_action( 'init' , array($this, 'init_function'));
    public function init_function() {
    	add_feed( 'custom', array($this, 'get_custom_feed') );
    }
    public function get_custom_feed($comment) {
    	echo 'custom feed'
    }

    Now the following url is working as expected:
    http://www.example.com/?feed=custom

    But with permalinks it is not working: http://www.example.com/feed/custom

    It works for existing feeds.

    get_feed_link( 'custom' ) returns the permalink and there wordpress returns Page not found.

    Does anybody have an idea why?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Do you flush_rules() on activation? This must be done so the permalink rewrite rule can be applied.

    Thread Starter jokr

    (@jokr)

    I think this cannot work. flush_rules() should be called during Plugin activation. The feed is added during the init hook.

    Moderator bcworkz

    (@bcworkz)

    Yes, calling flush_rules() on ‘init’ would be very bad! Even though it seems backwards, I think it could work if you also added the feed rewrite rule before flushing on activation. Rewrite rules don’t care if there is no actual feed defined yet, they are essentially just string manipulation.

    By the time the rewrite is actually executed, the feed will be defined and it should all work out. Unfortunately, I have not actually done this, it is just a theory that I think can work.

    Thread Starter jokr

    (@jokr)

    Flushing during activation indeed does the trick. I am not 100% sure, but it actually makes sense. The Init hook is executed before the activation hook and thus it works this way.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Permalink for custom feed not found’ is closed to new replies.