How do I load the .mo translate file to the back end of the plugin?
This only for front end:
function my_plugin_load_plugin_textdomain()
{
load_plugin_textdomain( 'my_plgin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'my_plugin_load_plugin_textdomain' );
Related
I am applying specific styles in Worpdress when I access a certain URL, for example:
misiito.com/?mobile
When I enter there I hide the header and footer. My code is the following:
if ( isset( $_GET['mobile'] ) ) {
wp_enqueue_style( 'adaptabilidad', plugins_url( 'css/mobile.css', __FILE__ ), array(), '1.0.0' );
}
if ( isset( $_GET['totem'] ) ) {
wp_enqueue_style( 'adaptabilidad', plugins_url( 'css/totems.css', __FILE__ ), array(), '1.0.0' );
}
My problem is that it doesn't change the links and places the /?mobile, please help me, how can I do it?
That is, I want all the buttons at the end to have /?mobile
I tried this, but it's obviously a bug:
add_filter( 'the_content', 'adaptabilidad_nattule_add_mobile_url' );
function adaptabilidad_nattule_add_mobile_url( $content ) {
$content = str_replace( 'href="', 'href="?mobile', $content );
return $content;
}
It's just a suggestion, but have you thought of creating duplicate pages (for each styles) with different URL slugs and simply using a plugin like "Simple 301 Redirects" to associate them with a "/something"?
Example:
yousite.com/page1-style2
yousite.com/page1-style27
I have developed 2 Wordpress plugins and I'm trying to load the needed css and js files in admin only where I need them.
I have written a function:
function ds_shortcodes_enqueue() {
$shortcodes_pages = array(
"shortcodes_plugin",
"add_shortcode",
"edit_shortcode"
);
$the_page = isset($_GET['page']);
if(in_array($the_page,$shortcodes_pages)){
// enqueue all our scripts
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
The function shoud load the files only on the pages with the slugs mentioned in the array.
Then, I have written a second plugin. Different name, different text domain, different functionality and I have used the same function:
function ds_videos_enqueue() {
$videos_pages = array(
"videos_plugin",
"add_video",
"edit_video",
"edit_video_category",
"video_categories",
"edit_video_level",
"video_levels",
"video_shortcode"
);
$current_page = isset($_GET['page']);
if(in_array($current_page,$videos_pages)){
wp_enqueue_style( 'ds-videos-style', plugins_url( '/admin/css/videos-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-videos-script', plugins_url( '/admin/js/videos-scripts.js', __FILE__ ) );
}
}
add_action( 'admin_enqueue_scripts', 'ds_videos_enqueue' );
Now here's the problem.
They load the files from both plugins on any plugin page in admin.
I just don't get it.
I couldn't find any way to fix this.
It seems in_array() returns always true.
I hope you can help.
Thank you.
admin_enqueue_scripts passes a page hook to the callback function.
So, you can do something like this,
function ds_shortcodes_enqueue($hook) {
if($hook != 'page_where_you_want_scripts') {
return;
}
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
Reference
I have also tried this but the in_array doesn't seem to work.
function ds_shortcodes_enqueue() {
$shortcodes_pages = array(
"shortcodes_plugin",
"add_shortcode",
"edit_shortcode"
);
if(in_array("shortcodes_plugin", $shortcodes_pages)){
// enqueue all our scripts
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
It should enqueue the 2 files only on the page with the slug "shortcodes_plugin". It loads the files everywhere.
There is a global variable in wp-admin called $pagenow which holds name of the current page, ie edit.php, post.php, etc.
You can also check the $_GET request to narrow your location down further, for example:
function ds_shortcodes_enqueue() {
$shortcodes_pages = array(
"shortcodes_plugin",
"add_shortcode",
"edit_shortcode"
);
if ( isset($_GET['page']) ) {
global $pagenow;
if(in_array($pagenow,$shortcodes_pages)){
// enqueue all our scripts
wp_enqueue_style( 'ds-shortcodes-style', plugins_url( '/admin/css/shortcodes-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-shortcodes-script', plugins_url( '/admin/js/shortcodes-scripts.js', __FILE__ ) );
}
}
}
add_action( 'admin_enqueue_scripts', 'ds_shortcodes_enqueue' );
function ds_videos_enqueue() {
$videos_pages = array(
"videos_plugin",
"add_video",
"edit_video",
"edit_video_category",
"video_categories",
"edit_video_level",
"video_levels",
"video_shortcode"
);
if ( isset($_GET['page']) ) {
global $pagenow;
if(in_array($pagenow,$videos_pages)){
wp_enqueue_style( 'ds-videos-style', plugins_url( '/admin/css/videos-style.css', __FILE__ ) );
wp_enqueue_script( 'ds-videos-script', plugins_url( '/admin/js/videos-scripts.js', __FILE__ ) );
}
}
}
add_action( 'admin_enqueue_scripts', 'ds_videos_enqueue' );
It seems in_array() returns always true.
<?php
$videos_pages = array(
'videos_plugin',
'add_video',
'edit_video',
'edit_video_category',
'video_categories',
'edit_video_level',
'video_levels',
'video_shortcode'
);
$current_page = isset($_GET['page']);
if(in_array($current_page,$videos_pages,true)){
echo 'I am debug point';
}else{
echo 'I am debug point 2';
}
exit;
?>
My plugin name is eventcal.Textdomain is eventcal. I have a language pack in /languages/ folder - eventcal-pt_BR.po and eventcal-pt_BR.mo. I have added plugin textdomain function
public static function eventcalLoadTextdomain() {
load_plugin_textdomain( 'eventcal', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
// in __constructor()
add_action( 'init', array(self::getInstance(), 'eventcalLoadTextdomain' ));
but its not working when i am changing my site language to portugese( Brazil )
Nothing is changing.everything is in english. How can i check plugin textdomain is working or not??
I also tried get_plugin_data( __FILE__ ); but not working
I'm trying to add new scripts and a css file to my child's theme on wordpress but i'm getting the following errors.
GET https://linton59.co.uk/wp-content/themes/simpleshift/css/lightbox.css?ver=4.3.0 net::ERR_ABORTED
(index):280 GET https://linton59.co.uk/wp-content/themes/simpleshift/js/lightbox-plus-jquery.js?ver=3.3.0 net::ERR_ABORTED
(index):279 GET https://linton59.co.uk/wp-content/themes/simpleshift/js/lightbox.js?ver=3.3.0 net::ERR_ABORTED
(index):68 GET https://linton59.co.uk/wp-content/themes/simpleshift/css/lightbox.css?ver=4.3.0 net::ERR_ABORTED
The following is the functions.php i'm using.
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:
if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'bootstrap','font-awesome' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );
// END ENQUEUE PARENT ACTION
add_action( 'wp_enqueue_scripts', 'theme_name_scripts', 20 );
function theme_name_scripts() {
wp_dequeue_script( 'simpleshift_public' );
wp_enqueue_script( 'myscript', get_stylesheet_directory_uri() .'/js/public.js', array( 'jquery' ), '1.0', true);
}
add_action( 'wp_enqueue_scripts', 'theme_light', 30 );
function theme_light() {
wp_dequeue_script( 'simpleshift_public' );
wp_enqueue_style( 'lightbox', get_template_directory_uri() . '/css/lightbox.css', array(), '4.3.0' );
wp_enqueue_script( 'lightbox2', get_template_directory_uri() . '/js/lightbox.js', array( 'jquery' ), '3.3.0', true );
wp_enqueue_script( 'lightbox3', get_template_directory_uri() . '/js/lightbox-plus-jquery.js', array( 'jquery' ), '3.3.0', true );
}
My child's theme has a css folder and js folder with the relevant files in it.
The last action is the only part not working.
get_template_directory_uri() will always return the URI of the current parent theme.
To get the child theme URI instead, you need to use get_stylesheet_directory_uri().
I want to integrate Option Tree framework with Wordpress theme without installing and activating plugin then how to do it ?
Since version 2.0 the plugin developer has included a number of filters that can be used in your functions.php. These include Theme Mode, and the comments within ot-loader.php state;
* For developers: Theme mode.
*
* Run a filter and set to true to enable OptionTree theme mode.
* You must have this files parent directory inside of
* your themes root directory. As well, you must include
* a reference to this file in your themes functions.php.
* #since 2.0
*/
define( 'OT_THEME_MODE', apply_filters( 'ot_theme_mode', false ) );
To activate Options Tree in your theme rather than as a plugin you include all the plugin files in the theme's root directory, ie
/wp-content/themes/my-awesome-theme/options-tree
and in functions.php you'd run this filter and then include the ot-loader.php file. I've shown this below, and I have also shown the show_pages filter;
add_filter( 'ot_theme_mode', '__return_true' );
add_filter( 'ot_show_pages', '__return_true' );
require_once ('option-tree/ot-loader.php');
The show_pages filter is useful because after you have set up your theme and your options you would then go in and set it to false so the client isn't given the main Options Tree admin menu and therefore can't start 'tinkering' and trash everything. You change it to;
add_filter( 'ot_show_pages', '__return_false' );
For anyone using a child theme and getting "failed to open stream" errors when using the OptionTree plugin in Theme Mode, do the following:
ot-loader.php, around line 128, change this:
if ( false == OT_THEME_MODE ) {
define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
define( 'OT_URL', plugin_dir_url( __FILE__ ) );
} else {
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
}
To this:
if ( false == OT_THEME_MODE ) {
define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
define( 'OT_URL', plugin_dir_url( __FILE__ ) );
} elseif ( is_child_theme() ) {
define( 'OT_DIR', trailingslashit( get_stylesheet_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_stylesheet_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
} else {
define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
}
The code checks if the theme in use is a child theme ( is_child_theme() ) and sets the dir and url using get_stylesheet_directory() and get_stylesheet_directory_uri().
Hope this helps out anyone else running into this issue.
It's really easy to integrate option tree :
Visit link below if you like to use it using same plugin slug:
Using same plugin slug
Or you can ingrate it in custom folder on your WordPress theme:
Using custom folder
Video Guide here (3:44 Sec):
Video Guide
add_filter('ot_show_pages','__return_false');
include_once('inc/theme-options.php');
Export setting in theme-options.php file.
add_filter('ot_theme_mode','__return_true');
require( trailingslashit( get_template_directory() ) . 'theme-option/ot-loader.php' );
add_filter('ot_show_new_layout','__return_false');