Disable header for a specific page in wordpress - wordpress

how can i disable header for this specific page. Is there any php function that disables the header for a specific page? In wordpress
Here is the link: https://techmax.ro/elementor-14408/

You can hide by CSS and using WP is_page function. check the below code.
function hide_header_on_some_pages(){
if( is_page( 'yourpagename' ) ){
?>
<style type="text/css">
.site-header {
display: none;
}
</style>
<?php
}
}
add_action( 'wp_head', 'hide_header_on_some_pages', 10, 1 );

Put this condition where the code is done to get the menu.
if(! is_page( 'your-page-slug' ) ){
      wp_nav_menu( array( 'theme_location' => 'your menu name', 'container_class' => 'my_extra_menu_class' ) );
}
Using this there is no extra dom element on this page.

Related

Add image next to site title in Wordpress website

I want to add a image to the left of the site-title: mysimpledevotion.com
How can I do that?
Would it be easier to make an image of both the text and pic, rather than trying to just add a small pic (icon) next to the text? I'm not talking about the favicon but rather the site-title MY SIMPLE DEVOTION on the front page.
I found two options to achieve this.
1. Using CSS before to inject the image
The major problem with this approach is that you cannot use relative paths; i.e, the image url must be absolute, otherwise it will not work consistently on all pages of the website.
To do so either add the following CSS to the "Additional CSS" part of your theme (when customizing it), or add it in the style.css of your custom child-theme (and make sure to add the style.css using the functions.php correctly).
.site-title a:before{
content:"";
background-image:url('http://path/to/my/image.jpg');
display: inline-block;
background-size: 1em 1em;
width: 1em;
height: 1em;
}
This will make the image correspond to the text size as well, and you can add additional CSS properties such as border-radius: 50%.
2. Using theme's filters to inject image
This approach heavily relies on the used theme to define appropriate filters where you could inject the image HTML. Here is an example of injecting an image to the Astra theme using a custom child-theme.
functions.php:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri() );
}
if( ! ( function_exists( 'wp_get_attachment_by_post_name' ) ) ) {
function wp_get_attachment_by_post_name( $post_name ) {
$args = array(
'posts_per_page' => 1,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'name' => trim( $post_name ),
);
$get_attachment = new WP_Query( $args );
if ( ! $get_attachment || ! isset( $get_attachment->posts, $get_attachment->posts[0] ) ) {
return false;
}
return $get_attachment->posts[0]->guid;
}
}
add_filter( 'astra_site_title', 'add_image_to_site_title' );
function add_image_to_site_title( $original_title ) {
$image = wp_get_attachment_by_post_name( 'my-image-post-name' );
$html = '<img src="' . $image . '" alt="" class="title-image">';
return $html . $original_title;
}
?>
style.css:
/*
Theme Name: My Astra
Template: astra
*/
.title-image {
display: inline-block;
width: 1em;
height: 1em;
}
I hope this helps :)
That is called favicon and can be added, if you are using theme which has that option included then can be checked by Theme Options within your wordpress admin (check on the left side). If it's isn't there then check Appearance >> Customize.
Even you cannot find there then check theme documentation. Try avoiding adding any additional code, it might conflict with existing.
Even it's not in theme documentation then do following steps to add it
Go to Appearance >> Editor
Click on header.php
Add the following code between <head></head>
<link rel="shortcut icon" type="image/x-icon" href="your-image-link" />

WordPress unlimited sidebars

Just wondering if someone could give me some advice on how to create unlimited sidebars for a WordPress theme.
So, basically I am looking into adding a meta box on posts and pages with a drop down list of all available sidebars, where the user can then select a specific sidebar for any post or page. This part I have figured out, however I would also like to add functionality here to allow users to create custom sidebars for any post or page. So, essentially the user could choose any sidebar for any post or page or create new sidebars for any post or page which then could be filled with widgets on the widgets page.
I half there, just not sure how to go about creating the functionality to create new sidebars.
There is a way to do it but it's a bit lengthy.
Create a customizer control to add multiple sidebars
The easiest way is to just take the custom control called Multi Input field from here. Also, be sure to add this custom control, and all the jQuery functionality that goes with it (in the .js file).
With that, add to your customizer file (or if you don't have a dedicated customizer file, to your functions.php file)
if(!function_exists('yourtheme_text_sanitization')){
function yourtheme_text_sanitization($input){
return wp_kses_post( force_balance_tags($input) );
}
}
/**
------------------------------------------------------------
SECTION: Sidebars
------------------------------------------------------------
**/
$wp_customize->add_section('section_sidebars', array(
'title' => esc_html__('Sidebars', 'yourtheme'),
'priority' => 0,
));
/**
Sidebars
**/
$wp_customize->add_setting('sidebars', array(
'default' => '',
'sanitize_callback' => 'yourtheme_text_sanitization',
));
$wp_customize->add_control(new Multi_Input_Custom_control($wp_customize, 'sidebars', array(
'label' => esc_html__( 'Sidebars', 'yourtheme' ),
'description' => esc_html__( 'Add as many custom sidebars as you need', 'yourtheme' ),
'settings' => 'sidebars',
'section' => 'section_sidebars',
)));
The first function is the sanitization function for your customizer sanitization callback.
So now you should have 'Sidebars' in your Appearance > Customize menu.
Create sidebars dynamically
But now you need to add your sidebars. If you have a dedicated sidebar file like sidebars.php where you register your theme sidebars, you can put this there, or in your functions.php file
if ( function_exists( 'register_sidebar' ) ) {
$sidebars=get_theme_mod('sidebars','');
if($sidebars!=''){
$sidebars = explode('|', $sidebars);
$i = 0;
foreach($sidebars as $sidebar){
$i++;
register_sidebar(array(
'name'=>$sidebar,
'id' => 'sidebar-'.$i,
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="sidebar-widget-heading"><h3>',
'after_title' => '</h3></div>',
));
}
}
}
This is the minimum you need so that you can add multiple sidebars in the theme, and they should appear in Appearance > Widgets.
Add sidebar metabox
Now adding a metabox to display them is relatively easy. In your functions.php, or a separate file where you add metaboxes to posts/pages/CPT, add
// Add metabox
add_action('admin_init', 'yourtheme_post_add_meta');
if ( ! function_exists( 'yourtheme_post_add_meta' ) ){
function yourtheme_post_add_meta(){
add_meta_box('post-sidebar', esc_html__('Select Sidebar', 'yourtheme'), 'yourtheme_post_sidebar_meta_box', 'post');
}
}
//Metabox
if ( ! function_exists( 'yourtheme_post_sidebar_meta_box' ) ){
function yourtheme_post_sidebar_meta_box( $post ){
$values = get_post_custom( $post->ID );
$custom_sidebar = (isset($values['custom_sidebar'][0])) ? $values['custom_sidebar'][0] : '';
wp_nonce_field( 'my_meta_box_sidebar_nonce', 'meta_box_sidebar_nonce' );
?>
<p>
<select name="custom_sidebar" id="custom_sidebar">
<?php
global $wp_registered_sidebars;
$sidebar_replacements = $wp_registered_sidebars;
if(is_array($sidebar_replacements) && !empty($sidebar_replacements)){
foreach($sidebar_replacements as $sidebar){
echo "<option value='{$sidebar['name']}'".selected($sidebar['name'], $custom_sidebar, false).">{$sidebar['name']}</option>";
}
}
?>
</select>
</p>
<?php
}
}
//Save Metabox
add_action( 'save_post', 'yourtheme_post_save_sidebar_meta_box' );
if ( ! function_exists( 'yourtheme_post_save_sidebar_meta_box' ) ){
function yourtheme_post_save_sidebar_meta_box( $post_id ){
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
return;
}
if( !isset( $_POST['custom_sidebar'] ) || !wp_verify_nonce( $_POST['meta_box_sidebar_nonce'], 'my_meta_box_sidebar_nonce' ) ) {
return;
}
if( !current_user_can( 'edit_pages' ) ) {
return;
}
if( isset( $_POST['custom_sidebar'] ) ){
update_post_meta( $post_id, 'custom_sidebar', wp_kses( $_POST['custom_sidebar'] ,'') );
}
}
}
And this should be it. A bit lengthy, but a way to add as many sidebars to your theme as you wish :)
Hope it helps.
Giving the users option to choose a sidebar is fine, but i dont think its a good idea to give them functionality to create their own sidebars. You will quickly get into the problem where you will have tons of sidebars in your widget area each for a different post.
However if i was in your situation, i would have created a single sidebar and then dynamically added widgets to this sidebar depending on the post that is being viewed. For the end user both will look the same. Anyways there is no right or wrong answer here, it depends on how you want to tackle the situation.

List Pages on Admin Menu in WordPress

I am trying to make my clients dashboard as simple as possible. Is there a way to do a wp_list_pages down the left side of the admin menu? Instead of clicking on Pages first.
Yes, it's a matter of using get_pages with add_submenu_page.
add_action('admin_menu', 'admin_pages_so_19817501' );
function admin_pages_so_19817501()
{
$pages = get_pages( array( 'parent' => 0 ) );
foreach( $pages as $p )
{
add_submenu_page(
'edit.php?post_type=page',
$p->post_title,
$p->post_title,
'edit_pages',
'/post.php?post='.$p->ID.'&action=edit',
null
);
}
}
You'll need some jQuery to manipulate the current CSS class from the submenu items.
See: Highlighting a Menu Item by Post Name.

WordPress Hide Page Editor Based on ID?

Is there anyway to hide the post editor wysiwyg on a page based on the page ID?
I have a few custom meta boxes and dont need it on this specific page..
I've tried the following but it doesnt do anything, the page has the id of 75 but its still showing up?
function remove_pages_editor(){
if(get_the_ID() == 75) {
remove_post_type_support( 'post', 'editor' );
} // end if
} // end remove_pages_editor
add_action( 'add_meta_boxes', 'remove_pages_editor' );
Any ideas..?
This can be done with an earlier hook, do_action('load-' . $page_hook);.
add_action( 'load-post.php', 'hide_specific_editor_so_15154969' );
function hide_specific_editor_so_15154969()
{
if( '75' == $_GET['post'] && 'edit' == $_GET['action'] )
remove_post_type_support( 'post', 'editor' );
}

How to get a slug name for a page without creating an admin page menu

I now use the add_submenu_page() function, but I don't want the edit page to appear in the admin menu.
I want to access the edit page from a list (another page) directly. But I need the slug as a hook_suffix.
I have in my-edit.php
/* Set up the administration functionality. */
add_action( 'admin_menu', 'my_edit_setup' );
function my_edit_setup() {
...
/* Add Edit Actionlist page. */
$myplugin->my_edit = add_submenu_page( 'myplugin', esc_attr__( 'Edit', 'myplugin' ), esc_attr__( 'Edit', 'myplugin' ), 7, 'my-edit', 'my_edit' );
...
In admin.php I have:
function my_admin_enqueue_style( $hook_suffix ) {
$pages = array(
'admin_page_projects',
'...my-edit'
);
if ( in_array( $hook_suffix, $pages ) ) {
wp_enqueue_style( 'myplugin-admin', trailingslashit( MYPLUGIN_URI ) . 'css/admin.css', false, '20110525', 'screen' );
You see I need the $hook_suffix, but I can't find out how to get this, without creating the admin menu item.
Example of how to create an invisible sub menu (it gets attached to the Dashboard, index.php) and the correspondent $hook_suffix.
The page can be accessed through http://example.com/wp-admin/index.php?page=sample_page_hidden.
add_action( 'admin_menu', 'admin_menu_so_11593510' );
add_action( 'admin_enqueue_scripts', 'admin_enqueue_scripts_so_11593510' );
function admin_menu_so_11593510()
{
add_submenu_page(
null, // doesn't shows up in the menu, submenu is attached to "index.php"
'Test',
'Test',
'edit_pages',
'sample_page_hidden',
'menu_options_so_11593510'
);
}
function menu_options_so_11593510() { echo 'Hello!'; }
function admin_enqueue_scripts_so_11593510( $hook_suffix )
{
if ( 'dashboard_page_sample_page_hidden' == $hook_suffix ) {
wp_enqueue_script( 'swfobject' );
}
}

Resources