When you create a custom post type, you should edit this option for setting you post type menu in admin:
1 |
'menu_position' => 5, // 5 - this is right under the Posts menu element |
This list is very usefull. It represents a hierarchy preset of menu elements in WordPress admin menu:
If you faced with situation when plugins classes hardcoded some data, you can override those for your theme. The main condition is a presence of special function before that class:
1 |
if( !class_exists( 'your class name' ) ) |
After that you should copy a file with this class. Then you create yourself plugin for example: wpm-vk-override-class. Copy a file ( for ex. it is vk.php ) with class in a plugin directory. A plugin main file will be like this:
1 2 3 4 5 6 7 8 9 10 |
<?php /** * Plugin Name: WPM override VK connect * Description: Override VK class * Version: 1.0.80 * Author: WordPress Monsters * Author URI: http://wpmonsters.org */ require_once( 'vk.php' ); |
But there is a little problem, you will see a Fatal Error after activation:
1 |
PHP Fatal error: Cannot declare class WOO_Slg_Social_VK, because the name is already in use in /home/space/workspace/cabinet/wp-content/themes/cabinet/includes/classes/vk.php on line 14 |
To understand this situation we have to know how the WordPress saveing an activated plugins in DataBase. Go to wp_options table and find a field – active_plugins. Lets have a look on value of this field:
1 |
a:8:{i:0;s:31:"query-monitor/query-monitor.php";i:1;s:34:"advanced-custom-fields-pro/acf.php";i:2;s:22:"cyr3lat/cyr-to-lat.php";i:3;s:51:"parent-category-toggler/parent-category-toggler.php";i:4;s:37:"woo-social-login/woo-social-login.php";i:5;s:91:"woocommerce-gateway-paypal-express-checkout/woocommerce-gateway-paypal-express-checkout.php";i:6;s:27:"woocommerce/woocommerce.php";i:7;s:17:"wpm-vk/wpm-vk.php";} |
It is a serialised array. Lets unserialize it:
1 2 3 4 5 6 7 8 9 10 11 |
Array ( [0] => query-monitor/query-monitor.php [1] => advanced-custom-fields-pro/acf.php [2] => cyr3lat/cyr-to-lat.php [3] => parent-category-toggler/parent-category-toggler.php [4] => woo-social-login/woo-social-login.php [5] => woocommerce-gateway-paypal-express-checkout/woocommerce-gateway-paypal-express-checkout.php [6] => woocommerce/woocommerce.php [7] => wpm-vk/wpm-vk.php ) |
Here you can set an order of activated plugins. But for our situation the better move would be deactivate conflict plugin (main plugin where we got a class). For me it is – woo-social-login. After deactivation you can activate your own plugin. There will be no errors, you can be sure. And activate a main plugin at the end. That’s all! Now your functionality have been overrided successfully!
There are no known methods to do the same result in your theme. You can override it in theme only if the class located in parent theme.
Create a sibbling folder near for parent theme. For example we have parent theme Twenty Fifteen Child. Create a folder twenty-fifteen-child with style.css file in it. It should consist:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/* Theme Name: Twenty Fifteen Child Theme URI: http://example.com/twenty-fifteen-child/ Description: Twenty Fifteen Child Theme Author: John Doe Author URI: http://example.com Template: twentyfifteen Version: 1.0.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: twenty-fifteen-child */ // If we want a parent styles in our child theme @import url("../twentyfifteen/style.css"); |
You will need to replace the example text with the details relevant to your theme.
The Template line corresponds to the directory name of the parent theme. The parent theme in our example is the Twenty Fifteen theme, so the Template will be twentyfifteen. You may be working with a different theme, so adjust accordingly.
The only required child theme file is style.css, but functions.php is necessary to enqueue styles correctly (below).
1 2 3 4 5 6 |
<?php function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); |
More details https://codex.wordpress.org/Child_Themes.
1 2 3 4 5 6 7 8 |
function wpm_search_filter( $query ) { if ( $query->is_search && ! is_admin() ) { $query->set( 'post_type', array( 'case' ) ); } return $query; } add_filter( 'pre_get_posts', 'wpm_search_filter' ); |
1 2 3 4 5 6 7 8 |
function wpm_add_custom_types( $query ) { if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'case' )); return $query; } } add_filter( 'pre_get_posts', 'wpm_add_custom_types' ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
add_filter( 'add_to_cart_fragments', 'wpm_header_add_to_cart_fragment' ); function wpm_header_add_to_cart_fragment( $fragments ) { global $woocommerce; ob_start(); ?> <a href="<?php echo site_url( '/cart' ); ?>" class="header__cart"> <i class="icon-bag"> <span class="header__cart-val mobile"><?php echo $woocommerce->cart->cart_contents_count; ?></span> </i> <span class="header__cart-val desktop"> <?php if ( $woocommerce->cart->cart_contents_count ): ?> <?php echo $woocommerce->cart->cart_contents_count; ?> items — <?php echo $woocommerce->cart->get_cart_total(); ?> <?php endif; ?> </span> </a> <?php $fragments['a.header__cart'] = ob_get_clean(); return $fragments; } |
1 2 3 4 5 6 7 |
/* Plugin Name: Subfolders Collections Description: Adds Collection Name to the begining url Version: 1.1 Author: Vyacheslav Gordeev Author URI: https://www.wpmonsters.org */ |