URL
-
Hello, is possible to remove /movie/ or /tv/ from the URL?
-
Hello,
First of all, it is not recommended to remove the slugs of custom post types, and technically, many errors may occur. However, you can safely change the slugs. I’ll explain both methods to you, but the responsibility is yours.I’m already considering adding a feature to change the slugs of custom post types in future updates, but if you want to do it now, you’ll need to get into some coding.
Go to the Admin panel, then navigate to Appearance -> Theme File Editor. In the editor, click on Theme Functions (functions.php) from the menu on the right. Add the following code at the very bottom of the editor:
function geekp_create_custom_post_type_function() {
register_post_type('gp_movie',
array(
'labels' => array(
'name' => __( 'Movie', 'geekpress' ),
'singular_name' => __( 'Movie', 'geekpress' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'film'), // Change the slug here, for example, I changed 'movie' to 'film'
'create_posts' => 'do_not_allow',
'show_in_menu' => false,
)
);
register_post_type('gp_tvshow',
array(
'labels' => array(
'name' => __( 'TV Show', 'geekpress' ),
'singular_name' => __( 'TV Show', 'geekpress' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => "series"), // Change the slug here, for example, I changed 'tv' to 'series'
'show_in_menu' => false,
)
);
register_post_type('gp_episode',
array(
'labels' => array(
'name' => __( 'Episode', 'geekpress' ),
'singular_name' => __( 'Episode', 'geekpress' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => "part"),
'show_in_menu' => false,
)
);
}
add_action('init', 'geekp_create_custom_post_type_function');As you can see here, by editing the part
'rewrite' => array('slug' => 'film'),
you can change the slug to whatever you want. Since I set the slug to ‘film’, the URLs will now appear as/film/movie-name
.After saving this, go to the Admin panel again and click on Settings -> Permalink, then update the permalinks to make the new links visible.
If you want to completely remove the slugs, the responsibility is yours. However, if you encounter any issues after testing, you can revert to the first method I showed you.
Directly paste the following code at the end of your functions.php file, as mentioned above:
function geekp_create_custom_post_type_function() {
register_post_type('gp_movie',
array(
'labels' => array(
'name' => __( 'Movies', 'geekpress' ),
'singular_name' => __( 'Movie', 'geekpress' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => '/', 'with_front' => false),
'show_in_menu' => false,
)
);
register_post_type('gp_tvshow',
array(
'labels' => array(
'name' => __( 'TV Shows', 'geekpress' ),
'singular_name' => __( 'TV Show', 'geekpress' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => '/', 'with_front' => false),
'show_in_menu' => false,
)
);
register_post_type('gp_episode',
array(
'labels' => array(
'name' => __( 'Episodes', 'geekpress' ),
'singular_name' => __( 'Episode', 'geekpress' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => '/', 'with_front' => false),
'show_in_menu' => false,
)
);
}
add_action('init', 'geekp_create_custom_post_type_function');
function geekp_custom_rewrite_rules() {
add_rewrite_rule(
'^([^/]+)/?$',
'index.php?gp_movie=$matches[1]',
'top'
);
add_rewrite_rule(
'^([^/]+)/?$',
'index.php?gp_tvshow=$matches[1]',
'top'
);
add_rewrite_rule(
'^([^/]+)/?$',
'index.php?gp_episode=$matches[1]',
'top'
);
}
add_action('init', 'geekp_custom_rewrite_rules');
function geekp_modify_post_type_query($query) {
if (!is_admin() && $query->is_main_query()) {
if ($query->get('page') == '') {
if (isset($query->query['name'])) {
$query->set('post_type', array('gp_movie', 'gp_tvshow', 'gp_episode', 'post', 'page'));
}
}
}
}
add_action('pre_get_posts', 'geekp_modify_post_type_query');After saving this, update your permalinks as described above…
Looking forward to your feedback.
Thank you for the response. We are using our category pages as our TV Show pages. We don’t want to change the structure of the site. So, I was thinking, is there a way to insert the movie/TV information by shortcode?
We generate the information by the plugin and them insert on the select page?
Also, when I buy my credits, trailer/imagens are automatically insert? All information on the demo page is inserted?
If you want, you can add the catalog anywhere you like using a shortcode.
[geekpress type=”movies”]
[geekpress type=”tvshows”]
Additionally, you can manage catalog pages via the GeeK!->Custom Pages section in the admin panel and create new pages.
As for the other question, token services allow you to fetch all the data for the movies using API services; you only need to add the trailers manually via YouTube. Other than that, actor information, movie details, and images can be automatically pulled using the API integration provided by the token services.
- You must be logged in to reply to this topic.