Add "custom page" without page - php

The title might not be completely clear, but I didn't know how to ask this in another way.
I want to build a system in Wordpress where the user can put some projects together where it would be on an url like http://mywordpress.com/projectbuilder/ or something like that.
Normally I would create an page in the admin menu and set it to a certain template and in the content I would put some text like: "Do not delete this page, this content is not shown".
But I think there must be a better way to add a custom page to a certain URL without adding it in the backend as a page with "useless content" since the content would not be changeable from the backend in this case.
I hope this makes sense. How could I go about that?
I think I could achieve this with a custom plugin but I can't seem to find any code how to go about that. I have found a way to add administration pages in the settings menu on the right. But I want to add a page to the website on the front end.

Sorry i didn't got your question properly. but some what say to create Custom post or taxonomy :
Please check below link
Custom Post and Taxonomies

In your functions.php file add this anywhere:
function themeslug_projects() {
$args = array(
'public' => true,
'label' => 'Projects',
'rewrite' => array( 'slug' => 'projects' ),
);
register_post_type( 'projects', $args );
}
add_action( 'init', 'themeslug_projects' );
Do save your permalink settings again after doing this, this will work surely then..

basically you can do this by creating a rewrite rule and then point to a file.
add_action('init', 'add_rewrite_rule');
function add_rewrite_rule(){
// add_rewrite_rule(REGEX url, location, priority (i.e. top is before other rewrite rules)
//basically tell wordress to add a query var if sidebar is added to url. change sidebar to what you want your link to be.
// i set up a custom post type to make this work called custompostype..it does nothing but just to give post_type a value.
add_rewrite_rule('^sidebar?','index.php?is_sidebar_page=1&post_type=customposttype','top');
}
// register a query var
add_action('query_vars','market_set_query_var');
function market_set_query_var($vars) {
array_push($vars, 'is_sidebar_page');
return $vars;
}
// associate a template with your quer_var
add_filter('template_include', 'market_include_template', 1000, 1);
function market_include_template($template){
if(get_query_var('is_sidebar_page')){
$new_template = (theme or plugin path).'/pages/yourpage.php'; // change this path to your file
if(file_exists($new_template))
$template = $new_template;
}
return $template;
}
after adding any rewrite rule, the changes wont take place until you go into settings->permalinks and hit the "save" button.

Related

Bypass OptionTree filters via functions.php

There are some basic options defined inside the basic file: ot-functions-admin.php
Since I have the OptionTree plugin implemented inside the theme files, I want to be able to update it every now and then.
That means, I will lose any custom options I have defined inside the file mentioned above.
For example, I have this inside the ot-functions-admin.php :
'menu_title' => apply_filters( 'ot_theme_options_menu_title', __( 'ACT', 'option-tree' ) ),
Which changes the title of the settings menu to "ACT" instead of "Theme Options".
I can change the text here of course, but in case of update, I will lose the changes and will have to redo them.
Is there any way I can write something like a filter inside functions.php that could help me achieve that?
add_filter( 'ot_theme_options_menu_title', 'ACT' );
I wrote the above, but unfortunately is not working.
Maybe the information below might be helpful to you:
'id' => 'ot_theme_options',
Thank you for your time.
I figured it out!
add_filter( 'ot_theme_options_menu_title', function ( $change_menu ){ return 'ACT'; } );

Custom Url structure for blog posts not for members and portfolios

If I change permalinks settings then all post types use that structure.
For example:
https://www.domain.dom/blog/%category%/%postname%/
then portolio item resolve as
https://www.domain.dom/blog/portfolio/item/
And I want to remove /blog/ from url when displaying members portfolios, faq, etc.
I found this, but don't know do I need to register new post type, put that in theme functions.php or what to do with that?
Really need some guide on how to achive that.
Thanks
It's easier than you think, add a single php file to the wp-content/plugins directory, add a plugin header comment, then one call to register_post_type(), e.g.:
<?php
/**
Plugin Name: My custom profiles
...
*/
add_action('init', function() {
register_post_type('my_custom_profile', [
'label' => 'Profiles',
...
]);
});

How can I change my page name in Wordpress? Do I need to edit my URL .htaccess?

My first post so I hope someone can help :)
I need to change http://designoriginal-test.co.uk/ef-travel/portfolio to http://designoriginal-test.co.uk/ef-travel/exhibitions
How can I go about doing this? There is no 'physical' page in the Wordpress backend so I am not able to change the slug manually.
Thanks in advance!
Zak
Looking at your site's source code I see body has classes post-type-archive and post-type-archive-portfolio, so it's not a taxonomy archive but a post type archive.
<body class="archive post-type-archive post-type-archive-portfolio nictitate-builder nictitate-header-style-1">
So, portfolio is a Custom Post Type. This allows two possibilities:
You're using a plugin to handle CPT's (eg: Custom Post Types UI).
In this case, you should have a submenu in your WP Dashboard where you could rename the post type.
Your CPT's are defined in your custom theme's (or custom plugin) source code
In this case, you should locate there (check your functions.php) some piece of code like this:
register_post_type( 'portfolio', … );
where you'll be able to rename the portfolio too.
In both cases I recommend you to backup your Database first. And if you're editing some source code files, backup them too before making changes.
Update:
After some research on the theme I've seen there's a free version of it. This version requires (via TGM Plugin Activation) a custom plugin from the same developer named Kopa Nictitate Toolkit.
function kopa_register_required_plugins() {
$plugins = array(
array(
'name' => 'Kopa Nictitate Toolkit',
'slug' => 'kopa-nictitate-toolkit',
'source' => 'http://downloads.wordpress.org/plugin/kopa-nictitate-toolkit.zip',
In this plugin they register the portfolio's CPT. So, check if you have this kopa-nictitate-toolkit folder in your /wp-content/plugins/. If so, there's a file named portfolio.php where they register the Portfolio CPT.
Edit:
You'll see that besides registering the CPT
register_post_type('portfolio', $args);
they also register some custom taxonomies.
register_taxonomy('portfolio_project', 'portfolio', $taxonomy_category_args);
register_taxonomy('portfolio_tag', 'portfolio', $taxonomy_tag_args);
You'll need to change this too so the theme won't broke. Check register_taxonomy docs.
Hope this helps!
Just go to the page and change the page name and its Permalink

Wordpress URL Routing, Multiple permalinks with different templates

This question is based on an unanswered question in Wordpress Development which has not gotten a solid answer.
I have a wordpress website which lists hotels. the url for a single hotel looks like:
/hotels/the-marriot-hotel
I also have a custom taxonomy for Locations, which allows me to browse the hotels in various locations, which works fine, the urls are like:
/Locations/Liverpool
For URL's like /hotels/* I would like to use a custom template, which I have done already and works fine.
The Problem
I also want to be able to drilldown the Locations taxonomy creating a breadcrumb type URL and also use a different template for the hotel page.
For Example, if a user is browsing /Locations/Liverpool and clicks the Marriot Hotel I would like it to click through to /Locations/Liverpool/the-marriot-hotel instead of /hotels/the-marriot-hotel and also use a slightly different template, which can also load a different sidebar and recommend other hotels in the area specific to the location slug in the URL
So basically I want two routes to a single post and a different template used based on the route used.
How would I go about implementing this?
What have I tried?
I've tried adding a new page and using a rewrite rule to point to it to be the locations hotel page.
I've tried adding a slug on the end of the /Locations/{location-slug} url and reading this in the page template and loading the hotel post instead of the list it doesn't seem to be working but also feels like a terrible hack anyway
An idea that I've had is to add a rewrite to the hotels/{slug} page and using code to detect the URL used and switch templates dynamically but I'm not sure this is the best approach
I have managed to get this working using the second method mentioned above (adding a rewrite to the locations landing page and checking for a query_var).
I will post the code below that I used but although this works and seems to be working very well, It does not feel like the best way of doing it. If someone know of a better way of doing this please post the answer.
I used this online post for reference.
Note: The listing page shows the list of hotels in the taxonomy in a side column down the side and shows the currently selected or a random one in the main content area. Which will explain how I am using the loop below.
function prefix_locations_rewrite_rule() {
add_rewrite_rule( 'Locations/([^/]+)/([^/]+)', 'index.php?locations=$matches[1]&hotel=$matches[2]', 'top' );
}
function prefix_register_query_var( $vars ) {
$vars[] = 'hotel';
return $vars;
}
function prefix_url_rewrite_templates() {
if ( get_query_var( 'hotel' ) && is_singular( 'hotel' ) ) {
add_filter( 'template_include', function() {
return get_template_directory() . '/taxonomy-locations.php';
});
}
}
add_action( 'template_redirect', 'prefix_url_rewrite_templates' );
add_filter( 'query_vars', 'prefix_register_query_var' );
add_action( 'init', 'prefix_locations_rewrite_rule' );
In my template file for the hotels landing page:
$hotelSlug = get_query_var( 'hotel', false);
if ( have_posts() ) {
while (have_posts()) : the_post();
if ($post->post_name == $hotelSlug) {
break;
}
endwhile;
}
This bit of code will iterate over the posts and if the hotel slug matches the query var it will break there so that the current post is the one we wanted.
We could just use a query here but as I already have a list of posts within the taxonomy I thought I'd just iterate over it. Below this I check to see if a specific hotel has been selected otherwise I show a random one from the list.
I am still to add additional logic and error handling to this code, I hope it helps someone with a similar issue

How to rewrite URL of Custom Taxonomy in Wordpress?

There are custom posts and taxonomy in my theme (Wordpress). I want to change url of them. At the moment I have sth like this:
www.mypage.pl/catalog/
I need rewrite url like this:
www.mypage.pl/parent/catalog/
I put the code:
'rewrite' => array(
'slug' => 'parent/catalog',
'with_front'=> false,
'feed'=> true,
'pages'=> true
),
This works for page www.mypage.pl/parent/catalog/myproduct, but www.mypage.pl/parent/catalog/ isn't.
Most likely, you just need to flush the permalinks to test your new one out.
After executing your custom post code, run flush_rewrite_rules(); to clear your code and implement your new permalink structure. (you only need to do this once, so remove the code after you've executed it)
http://codex.wordpress.org/Function_Reference/flush_rewrite_rules

Categories