• I’ve been looking at how to help with the permalink issue with this plugin.

    One way is for existing users to add this piece of code to your functions.php file

    function ontrapage_custom_post_type_mod( $args, $post_type ) {
    	if ( $post_type == "ontrapage" ) {
    		$args['rewrite'] = array( 'slug' => '/' ); 
    	}
    	return $args;
    }
    add_filter( 'register_post_type_args', 'ontrapage_custom_post_type_mod', 10, 2 );

    This will allow any type of permalink structures you have.

    For developers of this plugin, please update the way you register the ontrapage post type.
    Instead of
    'rewrite' => array( 'slug' => 'o' )
    change it to
    'rewrite' => array( 'slug' => '/' )
    This will make things so much simpler for what you are trying to achieve to make ontrapage custom post type behave like a wordpress page.
    Once this is done, the removeSlug() and interceptRequestTrickery() functions can be removed from the plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ultione

    (@ultione)

    Found a bug in my original solution.
    Please use this code instead

    function ontrapage_custom_post_type_mod( $args, $post_type ) {
    	if ( $post_type == "ontrapage" ) {
    		$args['rewrite'] = array( 'slug' => '/', 'with_front' => false );
    	}
    
    	return $args;
    }
    add_filter( 'register_post_type_args', 'ontrapage_custom_post_type_mod', 10, 2 );

    And for the plugin developer
    'rewrite' => array( 'slug' => '/', 'with_front' => false )

    Once the plugin is updated, the additional code to functions.php will not be required. If left alone, will not cause any issues either.

    Thread Starter ultione

    (@ultione)

    One thing to add, for users, once you have added the code to your functions.php Make sure that you flush your permalinks.
    Go to Settings > Permalinks and press save changes to refresh.

    Thread Starter ultione

    (@ultione)

    Sorry to get everyone’s hopes up.
    The solution will fix the permalink issue for ontrapages but will stuff up normal wordpress pages.

    So please DELETE this solution. Thanks.

    Thread Starter ultione

    (@ultione)

    I’ve managed to rework the solution for a possible workaround.
    Add below code to functions.php. And flush your permalink settings (Go to Settings > Permalinks and press save changes to refresh)

    function ontrapage_custom_post_type_mod( $args, $post_type ) {
    	if ( $post_type == "ontrapage" ) {
    		$args['rewrite'] = array( 'slug' => 'o', 'with_front' => false ); //set url so that it does not show anything in front
    	}
    
    	return $args;
    }
    add_filter( 'register_post_type_args', 'ontrapage_custom_post_type_mod', 10, 2 );
    
    function add_ontrapage_custom_rewrite() {
    	add_rewrite_rule('([^/]+)(?:/([0-9]+))?/?$', 'index.php?ontrapage=$matches[1]&page=$matches[2]', 'bottom');
    }
    add_action( 'init', 'add_ontrapage_custom_rewrite' );

    This was tested on a permalink structure of /blog/%postname%

    Everyone is free to try this solution, but as with any custom coded solution, it is not supported by ONTRAPORT.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Solution for permalink issue’ is closed to new replies.