How can i remove slug in custome post type url? - wordpress

In listings theme by Woothemes, the child them Bookclub.
when I add a book - as a custom post type - the url become as following :
mysite/book/post-name
I tried to remove the slug "book" but i failed
I want it to be
mysite/post-name

Much better then installing a whole plugin for this.
Tested with 4.3:
register_post_type( 'dummy', array(
//other custom posttype definitions
'rewrite' => array('slug' => '/')
) );
After this save your rewrite rules to make it work.

Actually it was quite easy, install the plugin "Remove slug from custom post type" to remove the '/product/' slug, no settings required. Install the plugin "SEO Ultimate" to remove the 'product-category' slug, in SEO Ultimate settings under 'Permalink Tweaker' check the 'Product Categories' and save. We use it for affiliates so cannot comment on other areas such as cart.

I don't know how well this plugin works, but here you go.
http://wordpress.org/extend/plugins/remove-slug-from-custom-post-type/

Related

WordPress archive/taxonomy location

I'm struggling with this, despite being okay at WordPress dev.
I've created a custom post type called links
I've also created a custom taxonomy called link-type
All works fine when using archive.php in the root of the theme.
However I want links to be a child page of resources so:
example.com/links/ would become example.com/resources/links/
And clicking on a taxonomy term link for example downloads would take you to example.com/resources/links/downloads/
I'm aware of has_archive and rewrite and with_front and slug but can't understand how to use these to achieve the aforementioned structure.
As always, expert help is much appreciated.
When you register your post type, just add whatever you want to the slug in the rewrite argument, forward slashes are acceptable in slugs.
$args = array(
'labels' => $labels,
...
'rewrite' => array(
'slug' => 'resources/links',
'with_front' => true
),
);
This will give you https://example.com/resources/links/, even if you have a page already at https://example.com/resources/.
I almost forgot, you'll need to make sure your flush your rewrite rules (this can be done programatically when the CPT is registered, or you can just go to your Settings > Permalinks option page and click Save Changes to accomplish the same thing one time.

Add fields to wordpress footer

I have a wordpress widget on my footer with contact details and the widget has editable fields:
Title
Email
Phone
Fax
Address
How can I edit this widget to include additional fields? I am new to wordpress and I am unsure if this is possible. In the help documentation for the widget it says the following:
How do I add additional fields to the contact widget?
Adding additional fields to the contact widget is as simple as adding a WordPress filter.
Here is an example:
add_filter( 'wpcw_widget_contact_custom_fields', function( $fields, $instance ) {
$fields['cellphone'] = [
'order' => 2,
'label' => __( 'Cellphone:', 'YOURTEXTDOMAIN' ),
'type' => 'text',
'description' => __( 'A cellphone number that website vistors can call if they have questions.', 'YOURTEXTDOMAIN' ),
];
return $fields;
}, 10, 2 );
However I am unsure as to where I would have to add this information
Widgets were originally designed to provide a simple and easy-to-use way of giving design and structure control of the WordPress Theme to the user, which is now available on properly "digitized" WordPress Themes to include the header, footer, and elsewhere in the WordPress design and structure. Widgets require no code experience or expertise. They can be added, removed, and rearranged on the Theme Customizer or Appearance > Widgets in the WordPress Administration Screens.
more details
2> visit blog i follow
if the widget don't have optionnal fields options altering it with new code can be the wrong approach. If the widget is updated you will loose your update.
The right way is to create a new widget with all the functions you need, maybe you can fork the existing widget and implementing your field.
Or you can just edit the footer.phpand including the widget logic in it.
Docs :
Widget api
Template development in wordpress

Any way to add metaboxes in custom settings page of custom post type in wordpress? [duplicate]

This question already has an answer here:
Add meta box to WordPress options page
(1 answer)
Closed 4 years ago.
Hi I would like to add metaboxes under custom settings page which is under a custom post type. I can create metaboxes for custom post types also I can create a theme options. But can't find any way to add the metaboxes on a custom settings page. Like my post type hierarchy is like below:
Products
- All item
- Add Item
- Product Category
- Product Settings
I want to add the metaboxes & create a options page on that settings page. Can you please guide me through this one.
I've been trying to follow this gist but can't find a way.
https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/options-and-settings-pages/theme-options-cmb.php
Also can you let me know if I can achieve something by tweaking this code where key|value operates
$cmb = new_cmb2_box( array(
'id' => $this->metabox_id,
'hookup' => false,
'show_on' => array(
// These are important, don't remove
'key' => 'options-page',
'value' => array( $this->key, )
),
) );
I've created the settings page by this code
add_submenu_page('edit.php?post_type=ch_product_showcase', 'Product Showcase Settings', 'Showcase Settings', 'edit_posts', basename(__FILE__), array( $this, 'chProductShowcaseSettingsOptions') );
I've done it many times. Use this code and tweak it to your needs:
https://gist.github.com/turtlepod/5203512
Found as a link in the comments of this page:
https://gist.github.com/bueltge/757903
Originally posted here:
Wordpress - Add meta box to options page
Normally I don't like answering with links to another site, but in this case the code is on gist and hopefully will never go away!

Wordpress Custom Taxonomy Template file

I registered custom post type named e-books in wordpress and have also registered a taxonomy for that as well here goes the code
register_taxonomy('ebookgenre', 'ebooks',
array(
'label' => __( 'Categories' ),
'rewrite' => array( 'slug' => 'category' ),
'hierarchical' => true,
)
);
But when i am listing all taxonomy from ebookgenre and linking them it is going to 404. please tell me which file or temlate should i use.
Thanks
See WordPress' template hierarchy documentation.
You must create a file called taxonomy-ebookgenre.php in your theme directory (or have one of taxonomy.php, archive.php, or index.php files).
Also, you should go to the WordPress Admin > Settings > Permalinks page. Simple visit the page, and WordPress will regenerate your rewrite rules. Your taxonomy will not work until you do this first. This is due to WordPress caching URL rewrite rules, so if you added your taxonomy after these were cached, the URLs won't work. Whenever you visit the permalink settings page, the rewrite rules are flushed and re-cached.

In WordPress how do you register built-in taxonomies with custom post types in code?

The WordPress codex has a lot of examples of how to register custom taxonomies with custom post types, but I couldn't find much about using built-in taxonomies (tags & categories) with cpts.
I have a cpt called listings, and I need to add the standard category and tag UI elements to the listing cpt page. I also need to do this with code in my functions.php, rather than using a plugin.
Not a problem at all. When you register the post type, just add this argument to the array:
'taxonomies' => array( 'category', 'post_tag' )
Suppose you defined your cpt (custom post type) by the following:
register_post_type('listings', $args); // where $args is an array of your cpt settings
Then you could use the following to add taxonomy:
// category-like:
register_taxonomy('listing_category', array('listings'), array('hierarchical' => true, ...));
// tag-like:
register_taxonomy('listing_tag', array('listings'), array('hierarchical' => false, ...);
In fact, I personally put those custom type definitions in my own plugin (not open for public as it provide my own site functionalities, which obviously not suit the others at all).
The problem of putting in functions.php increases the difficulty to change to a new theme (although changing theme is not so often, but for self-owned blog, it do happen in some day).
Moreover, the custom post types should be site-wide, not depending on the current theme. So semantically it should not be in the theme's directory.

Resources