Support » Plugin: Permalink Manager Lite » product/product url

Viewing 1 replies (of 1 total)
  • Plugin Author Maciej Bis


    The problem has been solved. To whom it may concern, please find the details and the suggested solution:

    The source of the issue is in the way DataFeedr imports the products – initially, the “product object” is a placeholder and it is empty.

    At the same time, the product slug is programmatically set to “product”, “product-2”, “product-3” and so on. The problem here is that Permalink Manager triggers the function that generates the product URLs before “the product object” is filled with the real/imported data.

    I prepared a temporary solution to prevent PM from saving the custom permalink if the product data is empty and then make it generate the custom permalink after the product is (programmatically) updated.

    Please paste the below code to functions.php file in your (child) theme directory:

    function pm_stop_product_uri($bool, $post) {
    	if(!empty($post) && $post->post_type == 'product' && empty($post->post_content)) {
    		return false;
    	return $bool;
    add_filter('permalink_manager_allow_new_post_uri', 'pm_stop_product_uri', 9, 2);
    add_filter('permalink_manager_allow_update_post_uri', 'pm_stop_product_uri', 9, 2);
    function pm_set_custom_permalink($post_id, $post) {
        global $permalink_manager_uris;
        // Update only selected product post type permalinks
        if(!empty($post->post_type) && $post->post_type !== 'product') { return; }
    	// Do not do anything if post is autosaved
    	if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; }
    	// Do not do anything if the post is manually updated/saved from "Edit product" page
    	if(isset($_POST['custom_uri']) || isset($_POST['permalink-manager-edit-uri-element-id'])) { return; }
        if(!empty($permalink_manager_uris)) {
            $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id);
            if($default_uri) {
                $permalink_manager_uris[$post_id] = $default_uri;
                update_option('permalink-manager-uris', $permalink_manager_uris);
    add_action('save_post', 'pm_set_custom_permalink', 100, 2);

    Best regards,

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.