Problem with the media library in wordpress - wordpress

I am building my own wordpress theme and I have such a problem. Media library doesn't work, I can't add any image to the page. I am using the latest version of wordpress.
Files available on github https://github.com/krysba/themes-wordpress
When I turn on the standard wordpress theme, the library works :(
I am asking for help in solving this problem.

If you have not tried, the first thing that i'll tring it's enable debug mode on Wordpress from wp-config.php and check if some alerts or errors can help.
define('WP_DEBUG', true);

I think that you must try to comment all function.php and debugging it row by row.
At the first check i've found a wrong use of the function add_theme_support and in the enqeueing files.
For example the right way to user add_theme_support is on the after_setup_theme action:
function my_setup_theme(){
add_theme_support('post-formats',array('gallery','link','image','quote','status','video','audio'));
}
add_action( 'after_setup_theme', 'my_setup_theme' );
Also the right way to enqueing scripts or styles is that:
function add_theme_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
See it on this page: https://developer.wordpress.org/themes/basics/including-css-javascript/

Related

How can I create a WordPress Plugin with custom CSS?

I want to create a WordPress Plugin where I want to add some css, and upon activation, those css will be in effect and be viewing in the website. Upon deactivation, the css will also be out of effect.
Any how I can do that? Or any documentation I can take help from?
You can follow Plugin Handbook for creating a plugin https://developer.wordpress.org/plugins/.
create a CSS file in plugin directory then upon plugin activation hook you can enqueue the CSS file using action 'wp_enqueue_style'.
You can add this to your main file to load your css file:
function add_my_css() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'style', $plugin_url . "/css/plugin-style.css");
}
add_action( 'wp_enqueue_scripts', 'add_my_css' );
Then create your plugin-style.css file and write your css.
Hope this helps

Disable prettyPhoto WordPress (Visual Composer)

Hi I'm trying to get WP Featherlight setup as the default lightbox, right now Visual Composer is using prettyPhoto. So I need to disable it, so that WP Featherlight will overwrite it.
I asked wpbakery and I got this response.
Hello, you can actually overwrite prettyphoto by adding prettyPhoto() in your functions.php and call another lightbox.
And from the plug-in author I got this:
Once prettyPhoto has been disabled, you shouldn't need to do anything
else to lightbox images on the site.
So it's pretty clear what I need to do. Disable prettyPhoto. But I don't know how to do that. Can I add a simple line to my child theme's functions.php? Or?
Any help would really be appreciated.
Thanks.
Place the following code in your theme's function file.
function remove_vc_prettyphoto(){
wp_dequeue_script( 'prettyphoto' );
wp_deregister_script( 'prettyphoto' );
wp_dequeue_style( 'prettyphoto' );
wp_deregister_style( 'prettyphoto' );
}
add_action( 'wp_enqueue_scripts', 'remove_vc_prettyphoto', 9999 );
I have tested this on my installation and it works flawlessly.
What it does is dequeues and deregisters the javascript and stylesheets that Visual Composer enqueues and registers throughout the plugin's PHP files for the various template elements and shortcodes that use the prettyPhoto lightbox.
The '9999' parameter enforces that the dequeuing/deregistering happens well after any enqueuing or registering took place earlier on in the loading of the plugin. Any number will do, but the higher the number the better.
You have to enqueue a custom javascript in your child theme where you override the following function:
function vc_prettyPhoto() {
}
in this way you disable prettyPhoto script initialization made by Visual Composer.
You can use code bellow to disable that javascript lib. Put that into your functions.php of theme
wp_dequeue_script( 'prettyphoto' );
wp_dequeue_style( 'prettyphoto' );
Also other page buider you can use is King Composer, which is faster VC
https://wordpress.org/plugins/kingcomposer/
Not sure if you solved the problem, but I have a solution (not very elegant, but it works).
I did buy ePix theme for a photographer and noticed that Masonry Media Grid from Visual Composer isn't fully responsive. So my soulution was to edit 3 files from wp-content/assets/js/dist. Those files are:
vc_grid.min.js
page_editable.min.js
js_composer_front.min.js
Just remove window.vc_prettyPhoto() or vc_prettyPhoto() from wherever they appear.
After that I installed Lightbox by dFactor, choose swipebox and used as selector prettyPhoto. Also I did force lightbox on link images. Now the lightbox is fully-responsive.
Hopefully this will help somebody :)
You can disable Pretty Photo. Use the below code in theme's function file, thats it.
function remove_scripts(){
wp_dequeue_script('prettyphoto' );
wp_deregister_script('prettyphoto' );
}
add_action( 'wp_enqueue_scripts', 'remove_scripts', 100 );
It will work.
I have tested on my own issue to deactivate some sliders from the Visual Composer and it works. An example how to deactivate the whole Flexslider, Nivoslider and Owl Carousel sliders in the Visual Composer plugin. Add this code into theme functions.php file:
add_action( 'wp_enqueue_scripts', 'deregister_vc_modules', 99 );
function deregister_vc_modules() {
wp_deregister_style( 'flexslider' );
wp_deregister_script( 'flexslider' );
wp_deregister_style( 'nivo-slider-css' );
wp_deregister_style( 'nivo-slider-theme' );
wp_deregister_script( 'nivo-slider' );
wp_deregister_style( 'owl-carousel' );
wp_deregister_script( 'owl-carousel' );
}

Loading jQuery via wp_enqueue issue

I'm having issues loading jQuery via wp_enqueue_script - I just discovered this is the correct way to pull in jQuery to avoid posible JS conflicts but I can't get it work. I'm using this example:
function my_init() {
if (!is_admin()) {
// comment out the next two lines to load the local copy of jQuery
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', false, '1.3.2');
wp_enqueue_script('jquery');
}
}
add_action('init', 'my_init');
I'm getting nothing when I check my source files. From what I can see the syntax is correct, I'm attempting to do this on a local WP install using XAMPP if that matters. Has anyone run into a similar issue? I've seen several questions about this but the fix usually comes down to a syntax error. I'm not seeing one. Any help would be much appreciated. Thanks!
Add the code below to your theme's functions.php in place of what you have.
The version of jQuery you were trying to load was outdated by the way.
Is this a custom theme you're building? If so are you using the wp_head and wp_footer tags?
By de-registering the built in version of jQuery and loading jQuery from the Google CDN you're reducing the time it takes to download the file but it isn't necessary. You could just load jQuery with wp_enqueue_script( 'jquery' );
function my_enqueue_jquery() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js', false, '2.0.3' );
wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_jquery' );
Wordpress 3.8 has jQuery.1.10.3.
wp_deregister_script('jquery') is not good for site.
So, you'd rather upgrade wordpress and use higher version of jQuery included in wordpress.
Please review this Wordpress Theme.
It's much easier to customize and has lots of features. Also easy to learn code tips.
Regards. HanaTheme.

I'm stuck trying to use wp_enqueue and Checking if the toolbar is activated on frontend

I am currently developing a theme and i am having issues when it comes to wp_enqueue. This is what i got but it isn't working.
function theme_name_styles() {
wp_enqueue_script( 'style-name',get_template_directory_uri() . '/css/dropdown.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_name_styles' );
secondly i am trying to tell if the toolbar is active on the frontend of wordpress or not and using conditions to display something if it is not active.
wp_enqueue_script is used to enqueue script , use wp_enqueue_style instead
other thing is its better to register script or style first before using
wp_register_script // to register script
wp_register_style // To register style
then enqueue using wp_enqueue_script wp_enqueue_style // learn more about it on codex
Try this :
add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );
function register_plugin_styles() {
wp_register_style( 'style-name', get_template_directory_uri() . '/css/dropdown.css' );
wp_enqueue_style( 'style-name' );
}
More info : http://codex.wordpress.org/Function_Reference/wp_register_style
For the toolbar, maybe you can find something here: http://digwp.com/2011/04/admin-bar-tricks/
There are specific functions to enqueue scripts and styles in wordpress. wp_enqueue_script is used to enqueue scripts only and wp_enque_style is used to enqueue stylesheets. These enqueued files will be attached at the point where you called the wordpress function wp_head. Note that these functions check for MIME type so that if you trying to enqueue a script using the wp_enqueue_style then it'll assume your stylesheet as a script and vice versa. You can see the type and explanation of the error if you use a debugger tool. The developers tool in google chrome is quite awsome. You can use this.
There is a function is_admin_bar_showing which can tell explicitly whether the admin bar is showing in the front end or not. http://codex.wordpress.org/Function_Reference/is_admin_bar_showing

How do I deregister style sheet from wordpress using functions.php?

I found this article here on how to deregister styles in wordpress. techotronic.de/how-to-de-register-style-sheet-wordpress/
Pretty simples I thought but I can't get my head round what he's trying to say. This is the code below...
add_action( 'wp_print_styles', 'custom_deregister_styles', 100 );
function custom_deregister_styles() {
wp_deregister_style( 'colorbox-theme1' );
}
Straight forward enough, for his plugin...
But if I wanted to deregister a style from another plugin I'm using, how do you find out what name to put in the code - wp_deregister_style( ' ???? ' );
I've tried the obvious, the stylesheet name...
add_action( 'wp_print_styles', 'custom_deregister_styles', 100 );
function custom_deregister_styles() {
wp_deregister_style( 'language-selector.css' );
}
and this is another method I found, but can't get my head around what I got to do?
add_action("gform_enqueue_scripts", "deregister_style");
function deregister_style(){
wp_deregister_style("gforms_css");
}
How does this deregister method work, and what do I need to look for in the plugin to get the relative name to get it to work. I'm very confused.
Appreciate any advice thanks!
UPDATE
I have just discovered the style sheet I'm trying to deregister is not loaded via wp_enqueue_style or wp_register_style.
See php file from plugin here https://gist.github.com/1442470
And look on Line 792 for language-selector.css
Find wp_register_style or wp_enqueue_style in the plugin folder. You'll find the name in that function call.
Update: You cannot remove this without editing the plugin, or resolving to ugly hacks like buffering all the output and filtering it at the end. That's the reason wp_enqueue_style or wp_register_style should be used for all stylesheets.

Resources