How to remove footer from some pages dynamicaly using function.php - wordpress

I am new to wordpress and learning Plugin development, I m creating a custom plugin, which display a list of page-title with check-boxes in admin section and on checking the selected pages footer should be remove from that pages, now I m facing issue with how to remove footer section?
I dont want to remove footer on single page, so custom template can not be used
I dont want to remove footer using css(like display none)
Can anybody help?

You can use Wordpress's remove_action to help remove unwanted php calls. More on that found here
Something like this:
function your__conditional_footer() {
if( is_front_page() )
return;
remove_action( 'theme_before_footer', 'theme_footer_widget_areas' );
}
Mind you, the function arguments are theme dependent.
Hope this points close.

Related

WordPre - Add ROLE attribute to menu items

Good evening everybody.
I need to add a custom attribute to my menu items.
This is what I believe I have to do... but nothing is added.
add_filter( 'nav_menu_link_attributes', 'add_role_attribute_to_menu' );
function add_role_attribute_to_menu( $atts ) {
$atts['role'] = 'button';
return $atts;
}
I'm using WP 5.6 and Astra free theme.
I noticed that also Astra uses this filter to add specific categories to the menu items, with no results!
What's the matter?
Maybe I have to include the add_filter inside another call?
Thanks
EDIT
I forgot to say that I use "Elementor – Header, Footer & Blocks Template" to manage the header of the site. https://wordpress.org/plugins/header-footer-elementor/

Remove menu item from sidebar

Someone created a menu in wordpress sidebar. I need to remove that permanently. Can anybody say how can we do that? In this image ( the wordpress dashboard image which you going to see when open this link below ) you can see portfolio, careers, team etc. These are the links someone added before and we need to remove. Thanks :)
http://dev.netbramha.in/projects/image/Untitled.pngenter code here
You can remove menu items using action hook.
function remove_dashboard_menus(){
remove_menu_page( 'wpcf7' );
}
add_action( 'admin_menu', 'remove_dashboard_menus' );
remove_menu_page parameter you can pick up from address URL page parameter like this : http://localhost/wpdemo/wp-admin/admin.php?page=wpcf7
If you are using CPT UI plugin, you can open it in your admin and you will find the portolio cpt created there. Just delete from there.
If you are not using CPT UI plugin, you can go to functions.php and remove the code where portfolio code is defined.
In functions.php check add_action() function. You can find these menu items there.

wordpress : how to add categories and tags on pages?

I have generated pages using a custom template by creating a php file in my theme directory
something like :
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
and then adding a new page on the dashboard selecting this new template
How can i now associate tags and categories to each pages ?
Is creating posts instead of pages the only solution?
Even better is to add to functions.php in your theme folder:
function myplugin_settings() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'myplugin_settings' );
Tried using the accepted answer but for some reason it only shows the Post types and none of the Pages shows in the category page. E.g. /category/entertainment/
To fix that, I have to do this:
// add tag and category support to pages
function tags_categories_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
Try this:
add_action( 'init', 'wpse34528_add_page_cats' );
function wpse34528_add_page_cats(){
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
Not at all helpful to say 'download plugin' for beginners who are most likely not going to have downloaded wordpress and are therefore not able to install said plugin. Here is some short code for those like me that have been scouring the web for something that actually works on regular pages with regular accounts - ie you're not a developer.
First, make sure you have your pages in your menu set up properly.
YOU DO NOT NEED TO MAKE YOUR PAGES 'Categories' or 'Tags'!
This wouldn't give you actual pages to then go and edit, so if you are wanting to add sliders, text, an intro, or anything for that matter, you wouldn't be able to.
Then go to WP Admin > Pages
Select a page to edit and go to the text editor instead of visual editor (far right hand side tab)
Then past the following short code:
[display-posts category="hair,makeup,reviews,beauty" posts_per_page="10" include_date="true" text-decoration: none date_format="F j, Y" order="DESC" include_excerpt="true" wrapper="div" image_size="large"]
<
(The shortcode collects all the posts that you have assigned certain categories in your blog posts i.e. mine was hair and beauty. So obviously change yours to ones that are appropriate. It then allocates how many posts (mine was 10), the date (in descending order,) with a large image and an excerpt of the post)
this plugin sorted me out :
http://wordpress.org/extend/plugins/add-tags-and-category-to-page/
with the standard instructions :
Upload the plugin files to the /wp-content/plugins/ directory
Activate the plugin through the 'Plugins' menu in WordPress
Use the setting page of the plugin from Settings > Add Tags And Category For Page.

Wordpress Div Tags in Posts

The TinyMCE editor in WordPress 3 is removing my div tags if I switch from HTML view to visual and update my page. What would be the best way to prevent this from happening?
I have a styled horizontal rule that I enter into the pages/posts by putting the following code:
<div class="hr"></div>
You could also create a shortcode by entering the following in your themes functions.php file:
function hr_shortcode( $atts, $content = null ) {
return '<div class="hr"></div>';
}
add_shortcode( 'hr', 'hr_shortcode' );
Then you would just need to add [hr] into your post.
Have you tried converting them to entities?
>div class="hr"<>/div<
Wordpress strips certain tags out automatically. Try this plugin that allows you to specify which tags you don't want stripped.
http://wordpress.org/extend/plugins/tinymce-valid-elements/
You can also manually hack the tiny MCE config files, but I think sticking with the plugin is the easiest and safest bet.

why is the <?php wp_head ?> tag creating a top margin at the top of my theme header

Hey people, I've been coming here for a while but just decided to join.
I'm new to php and I'm trying to make a website with WordPress as the CMS.
Anyway, I'm basically making my own theme because I don't want my website to look like a blog, and it's going pretty smoothly so far but theres this huge top margin gap in the browser even when I set margins to 0px.
I tried trial and error and found out that it's being caused by: <?php wp_head(); ?>
It's two different things.
1. wp_head() function
wp_head() is a template tag to print whatever plugin / theme specific function used by wordpress action. Read codex for more detail about it.
2. The admin bar
The top margin, is generated by wordpress's admin bar.
To fix this for logged in users you can do a couple of things:
Disable admin bar from the admin:
Go to admin panel
Users >> User Profile
Uncheck 'when viewing
site' on 'Show Admin Bar'
Remove the admin bar from your theme entirely:
Open your functions.php
Add this to it:
function my_function_admin_bar(){ return false; }
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
Remove only the code which creates the css:
Open your functions.php
Add this to it:
function my_filter_head() { remove_action('wp_head', '_admin_bar_bump_cb'); }
add_action('get_header', 'my_filter_head');
Note: Extensive updates are from #hitautodestruct
you neeed to call wp_footer() in your footer
just insert this line <?php wp_footer();?> into your footer.php file
If you have updated your wordpress install to the latest version.. there seems to be some bug with the admin bar...
were it would produce an inline stylesheet appended to the top of your pages.. causing the margin-top:28px
see here
1 recomendation is to put a new function into your functions.php file located in your theme folder.. this will completly remove the bar, so no users of your theme will have any of the same issues!
function my_function_admin_bar(){
return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
Not sure if this will help.. but worth a shot.. also turning off the admin bar while viewing the front end of the site under your profile page..

Resources