Do i need to remove this wp-block-library-css (Gutenberg CSS)? - html

I just want some clarification and advice regarding this tag in WordPress.
This tag is showing in my WordPress head even I'm not using Gutenberg.
link rel="stylesheet" id="wp-block-library-css"
Is this necessary or required?
Do I need to remove this to improve page speed?
Is there any effect if I remove this tag?
Please enlighten me.
Thank you

I use to remove this stylesheet on websites which are not using Gutenberg.
I don't think there is other effect than removing this stylesheet, you can do it safely.
To go a bit further, you can remove it only for some post types like
function remove_wp_block_library_css() {
if( !is_singular('post') ) {
wp_dequeue_style( 'wp-block-library' );
}
}
add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css' );

If you are not using Gutenberg at all, you can unload styles further more like this :
// Unload Gutenberg-related stylesheets.
add_action( 'wp_enqueue_scripts', 'remove_block_css', 100 );
function remove_block_css() {
wp_dequeue_style( 'wp-block-library' ); // Wordpress core
wp_dequeue_style( 'wp-block-library-theme' ); // Wordpress core
wp_dequeue_style( 'wc-block-style' ); // WooCommerce
wp_dequeue_style( 'storefront-gutenberg-blocks' ); // Storefront theme
}

Related

Move a particular div to top programmatically in wordpress in all posts

I have a particular div in all wordpress posts, I want to move them to the top , so that its the first paragraph. I have more than 3000 posts in the wordpress site. So moving each one isn't an option for me.
I tried this,
function add_this_script_footer(){
$specialDiv = document.getElementById("medtab");
$movedDiv = specialDiv;
$entryContent = document.getElementsByClassName("entry-content")[0];
entryContent.insertAdjacentElement('afterbegin', movedDiv);
specialDiv.remove();
}
add_action('wp_footer', 'add_this_script_footer');
have added this to the code snippet plugin, but doesn't work.
This is the error am getting when adding it to functions.php
syntax error, unexpected 'var' (T_VAR)
You can write some simple javascript and place it in the footer to programmatically remove the specified div from your content and move it to the top of the content.
First add your JS to the footer. (This goes into your functions.php of your child theme. You can also use Code Snippets plugin to add it if are not using a child theme)
function add_this_script_footer(){ ?>
//YOUR JS CODE HERE
}
add_action('wp_footer', 'add_this_script_footer'); ?>
As you didn't share your code, I'm assuming that your special div has an id. In that case you can select it with.
var specialDiv = document.getElementById("your-div-id");
var movedDiv = specialDiv; // Copy moved Div to a new variable
You can then remove it using remove() method.
specialDiv.remove();
Finally, you can insert the movedDiv to the beginning of entry-content (Which should be the main content area div) by using insertAdjacentElement()
var entryContent = document.getElementsByClassName("entry-content")[0];
entryContent.insertAdjacentElement('afterbegin', movedDiv);
EDIT2: The problem was, movedDiv had to be "cloned" with .cloneNode
add_action( 'wp_footer', function () { ?>
<script>
var specialDiv = document.getElementById("medtab");
var movedDiv = specialDiv.cloneNode(true);
var entryContent = document.getElementsByClassName("entry-content")[0];
entryContent.insertAdjacentElement('afterbegin', movedDiv);
specialDiv.remove();
</script>
<?php } );

Add ACF fields to Post Edit Admin Page / edit.php

I am trying to add a few custom fields to the edit.php page ( Post List Page )
It is a few settings like asking the user whether post must be displayed in 2,3 or 4 columns w, and I specifically want it on this page.
I have found a way to add content with a function to the right place without editing the wp-admin/edit.php or wp-admin/custom-header.php
add_action( 'load-edit.php', function(){
$screen = get_current_screen();
if( 'edit-post' === $screen->id )
{
add_action( 'all_admin_notices', function(){
echo '<h2> === Add ACF Fields here === </h2>';
});
});
i am also halfway in adding a location rule in ACF:
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
$choices['Post']['post_edit_screen'] = 'Post Edit Screen';
return $choices;
}
But how do now create a location rule to show my ACF fields here?
Thank you
I spent hours trying to extend the ACF_Location class without success.
The ACF Extended WordPress plugin provides the desired functionality.
You can find the GitHub repo here.
I believe this is the class that extends the ACF location functionality we both needed. #see acfe_location_post_type_archive class here

Add default code in wordpress post

I want to add a simple code to all new post by default
I tried to used this code in .function.php (wpbeginner)
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "If you like this post, then please consider retweeting it or sharing it on Facebook.";
return $content;
}
I am using plugin named Shortcodes Ultimate
Code:
[su_spoiler title="Download The File" style="fancy" icon="chevron-circle"]Here[/su_spoiler]
I tried to normal use simple html and CSS code but it show the same error for both cases
https://i.stack.imgur.com/wgAs4.png
Try this -: wrap your code is a single quote as you are already using double quotes.
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = '[su_spoiler title="Download The File" style="fancy" icon="chevron-circle"]Here[/su_spoiler]';
return $content;
}

Remove pretty photo style and script if not exist wordpress

I need to dequeue or remove style and script related to "pretty_photo" from my theme but load it again only when it called or needed
i have this code in my functions.php
wp_enqueue_style('pretty_photo',
MASTER_THEME_DIR . '/addons/prettyphoto/prettyPhoto.css',
array(), false, 'all');
please someone help me.
Thank you!
I get it to work finally .. The code is:
add_action( 'wp_enqueue_scripts', 'pretty_photo_styles', 100 ); function pretty_photo_styles() { if ( ! is_single() ) { wp_dequeue_script( 'pretty_photo' ); wp_dequeue_style( 'pretty_photo' ); }}
Please someone correct it if i missed anything! i tried it and it worked for me.
Thank you all.

Output post for second wordpress editor

I recently added a new editor to all my pages and posts admin area with the Wordpress 3.3 new feature to do this
add_action( 'edit_page_form', 'my_second_editor' );
function my_second_editor() {
// get and set $content somehow...
wp_editor( $content, 'mysecondeditor' );
}
My question is how do I output what I enter in this second editor on my website/page? Do I need to make a custom loop? The codex is not very helpful unfortunately.
Thanks
You'll need get_post_meta(), use it like:
echo get_post_meta(get_the_id(), 'mysecondeditor');
Read more: http://codex.wordpress.org/Function_Reference/get_post_meta
To save the data entered in your second editor you'll need this code in your functions.php file:
add_action( 'save_post', 'save_post', 10, 2 );
function save_post( $post_id, $post ) {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
update_post_meta( $post_id, 'mysecondeditor', stripslashes( $_POST['mysecondeditor'] ) );
}
So after that he's the full code for your second editor:
wp_editor( get_post_meta(get_the_id(), 'mysecondeditor', true), 'mysecondeditor' );
The true above makes sure only a single variable is returned and not an array so you can use it right away.
user2019515I's (Apr 18 '13 at 12:06) answer works for me, I can add text and gallery, but when I display that with this code:
<?php echo get_post_meta(get_the_ID(),'mysecondeditor')['0']; ?>
I got gallery code instead of the images, so:
mytext [gallery ids="102,62"]
How could I display the text (mytext) and the images too?