Custom page classes not showing up in code - css

I tried adding page classes via Appearance => Menus => Screen Options => CSS Classes, but when I update my pages the classes don't show up.
I tried with another theme, it works, so my problem is theme-related. I didn't develop this theme, I took it back from another developer. Can someone explain me what I should look for in the code to make it back to normal?
Thank you for the help.

It could be a couple of things, where to look first.
Look for some standard functions are in the templates file such as body_class(), post_class(). As it print standard Wordpress used class within the context it needs to.
If its more menu related look for add_filters() within the functions.php filters that allow css to be added or removed such as.
add_filter('nav_menu_css_class' , 'some_function_called' , 10 , 2);
function some_function_called($classes, $item){
if(is_single() && $item->title == "Blog"){ //Notice you can change the conditional from is_single() and $item->title
$classes[] = "special-class";
}
return $classes;
}
Best of luck.

Related

Change the default global edit link that lists my CustomPostType (edit.php?post_type=CPT), to use a plugin page link instead

I'm working on a plugin (with a https://wppb.me/ plugin boilerplate base, if relevant).
I defined my custom post type, with the editor options I want, that I can edit with the default /wp-admin/post.php?post={id}&action=edit
The listing of those CPT is done on my plugin pages only (no specific menu for the CPT) and I want to keep it that way.
Problem:
I'd like to change the base edit link of this post type when no ID is specified
( eg : /wp-admin/edit.php?post_type=CPT ) to be the URL of my plugin
( eg : /wp-admin/admin.php?page=myplugin )
This, mostly because in Gutenberg Editor Fullscreen, the top left wordpress logo links to the /wp-admin/edit.php?post_type=CPT that I don't wont to use nor show. I'd like this link to be a page of my plugin (here, it would be the homepage of my plugin)
I tried with a filter on get_edit_post_link when there is no ID provided, but it doesn't seem to be the correct way to fix my problem.
Any tips or help to get me in the right direction in my research are welcome !
I found one of the possible solutions. After entering the site, you must redirect the user.
function wp_custom_update_meta_cache_filter() {
global $pagenow, $typenow;
if ( $pagenow == 'edit.php' && $typenow == 'CPT' ) {
wp_safe_redirect();
die();
}
}
add_action( 'admin_init', 'wp_custom_update_meta_cache_filter' );
Based in (233 line):
https://github.com/dipolukarov/wordpress/blob/master/wp-content/plugins/woocommerce/admin/woocommerce-admin-init.php

how to use filter or rewrite to change parameters to output desired permalink in child theme

i have asked my theme provider, i want to change 'TEAM-MEMBER' to 'AUTHOR'. As like follow
Now link is : http://www.domain.in/team-member/authorname
but i want make this : http://www.domain.in/author/authorname
my theme provider say that, Here is the code to update the team-member to author.
<?php
add_filter( 'pgscore_register_cpt_teams', 'pgscore_extend_cpt_teams' );
function pgscore_extend_cpt_teams( $args ){
// get current rewrite rules
$rewrite_new = $args['rewrite'];
// Change permalink slug to 'author'
$rewrite_new['slug'] = 'author';
// update rewrite rules with updated rewrite rules
$args['rewrite'] = $rewrite_new;
// return updated parameters
return $args;
}
?>
Add this code in the child theme (we assume that, you are using a child theme. If not, then create and use it).
We suggest using Child Theme for any customization. It can avoid losing any customization in the case of updating the theme.
but i have put follow code in function.php in child theme, showing this syntex, expected error.
this is screen shot of error
Please Remove <?php on line number 7. You have start unnecessary php under php file. remove <?php and try to save again I hope it working well.

Finding hooks Wordpress

I know there are lists of hooks for WordPress like --> http://adambrown.info/p/wp_hooks/hook
But if I want to find hooks for a plugin like WC Vendors there is a much shorter list of hooks on their website.
Are 'do_action' and 'apply filter' functions the only thing we can modify?
If given a class like --> https://github.com/wcvendors/wcvendors/blob/master/classes/admin/class-product-meta.php#L10, is there any way to modify it?
Are we limited to the do_action hooks or is there a way to modify other areas as well? Can we use the WordPress hooks to hook into the WC Vendors plugin as well?
Mostly you should try to accomplish any task with hooks, but some tasks are just not possible without actually modifying the actual code. But we all know its not good to modify core code, as all changes disappear after an update. So instead of modifying a class, you can extend it. You can override the current features and also add new ones. Extending a class is as easy as using a relavant hook in functions.php and then extending it in the same file or requiring it from another file. Here is an official tutorial on how to add a new shipping method to the woocommerce shipping class.
Sometimes you dont even need all the hooks, you just need to find the ones that are running on a specific page. For this you can use the code below to list all the current hooks.
$debug_tags = array();
add_action( 'all', function ( $tag ) {
global $debug_tags;
if ( in_array( $tag, $debug_tags ) ) {
return;
}
echo "<pre>" . $tag . "</pre>";
$debug_tags[] = $tag;
} );
Or you can use this plugin "simply show hooks"which is really helpful while development as it gives you an idea of where each hook is being triggered on the page.

remove custom meta boxes not working

what I was trying to do here is to remove some custom fields that I created when a template is selected, aka when I select certain template I want to hide or show specific metaboxes.
The code I have is the following but it isn't working at all (thats to say that it doesn't remove any metaboxes) and I would like help to see what's wrong with it or if what I'm trying to do it's just not posible.
add_action('admin_init','my_meta_init');
function my_meta_init(){
$template_file = get_post_meta(get_the_ID(), '_wp_page_template', TRUE);
if (($template_file == 'thanks-template.php') || ($template_file == 'view-template.php'))
{
remove_meta_box('my_meta_box_id','page','normal');
remove_meta_box('my_meta_box_id_2','page','side');
remove_meta_box('my_meta_box_id_3','page','side');
remove_meta_box('dynamic_sectionid','page','normal');
} else
{
remove_meta_box('my_meta_box_id_4','page','normal');
}
}
Thanks you for the comments and answer, everyone helped. The problem was on the hook I was using, I changed it and now it's working perfectly :
add_action('admin_head','my_meta_init');
You may need to change the HOOK you are using to hook in your function.
That is you need to hook into admin_menu instead of admin_init as the metaboxes might not exist the moment you are trying to remove them. So a certain order is needed to make sure metaboxes removal call is made when actual metaboxes are generated and exist.
I tested following code on my localhost and it hid the Author div/metabox fine when used this code snippet:
function remove_page_fields() {
remove_meta_box( 'authordiv' , 'page' , 'normal' ); //removes author
}
add_action( 'admin_menu' , 'remove_page_fields' );
Another Approach:
By the way, as I think about the situation you are facing, maybe add the metaboxes/custom fields in such a way, that they are shown only to the pages we are meant to. I have worked on projects where I need to show some metaboxes only when certain template is selected.
I use CMB2 class to generate metaboxes mostly, if you happen to use that or something similar, you may use this parameter to specify the page templates https://github.com/WebDevStudios/CMB2/wiki/Display-Options#limit-to-specific-page-templates

Replacing WordPress core functionality with a plugin

I'm creating a WordPress plugin for a custom menu layout. I am well aware that I could just as easily implement this menu directly into the theme and I've read up quite thoroughly on the features and limitations of wp_nav_menu(), plus I have already tried and tested every plugin already created for replacing the default WordPress menu.
I wish to use a plugin since my client will be implementing this on several different WordPress sites, many of which run on different themes - and most of those are themes which I did not create and I do not wish to re-write their code in case they update the theme in the future.
When I've looked into a way to implement the menu into the theme I found that there are only two good methods since there is no hook or filter called at menu display time. The first is to change the theme to look for the plugin (this is similar to the method used by PixoPoint and many other menu plugins):
header.php:
if(function_exists('pixopoint_menu')){
pixopoint_menu();
} else {
wp_nav_menu();
}
The second method is a walker class:
plugin.php:
class my_walker_class Extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
/*
* Etc. Etc.
*/
}
}
header.php:
wp_nav_menu( Array( 'walker' => 'my_walker_class' ) );
However as you'll note both of these methods require a modification to the standard header.php file.
Ideally I would like to simply replace the wp_nav_menu() function if my plugin is loaded, as this would give my plugin support for the majority of themes without having to edit any of the theme files. Is there a good way to do this? Or is there a better way to write a menu plugin which I am not seeing?
You can use the wp_nav_menu_args filter to modify the arguments passed to wp_nav_menu, so you can specify your custom walker class.
add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args_filter');
function my_wp_nav_menu_args_filter($args = array()) {
$args['walker'] = new my_walker_class();
return $args;
}

Resources