Hide language switcher names - css

I am trying to hide language names in the language switcher and show only flags. WPML support told me, that the standard language switcher is provided by the theme (Flatsome), so they couldn't help.
Flatsome support told me, that can't help with custom solutions.
I was trying to find by myself through the „inspect page“ what is responsible for those language names, but all i found were affected on the whole header-main content. Not found, what is responsible only for „language names“.
inspect page
So i asked WPML support again, what i can use for CSS or something to hide those names and the answer was: "function engage_header_langs()". And i do not understand what to do next.
Can anyone help with this?

The function you were given can likely be hooked into if you review your plugin's documentation.
However, this can be done with some simple jQuery as shown in the snippet below. If you are using a custom JS file you can add this there (assuming you are already out of noConflict mode). If not, you can use the last snippet noted for your functions.php file.
Update: I updated the script to adjust the css to display after it has removed the text. You will now need to add that to the functions.php file and the line of css above that to style.css (or wherever you are putting your css)
$(".has-dropdown.header-language-dropdown a").contents().filter(function() {
return this.nodeType === 3;
}).remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li class="has-dropdown header-language-dropdown">
<a href="#">
"Eesti"
<i class="image-icon">
<img src="https://cdn.pixabay.com/photo/2015/11/12/16/24/flag-1040595_960_720.png">
</i>
</a>
</li>
</ul>
//Add this to style.css
.has-dropdown.header-language-dropdown a {
display:none;
}
//If adding to WordPress functions.php, use this block.
function add_script_to_head() {
?>
<script>
jQuery(document).ready(function($) {
$(".has-dropdown.header-language-dropdown a").contents().filter(function() {
return this.nodeType === 3;
}).remove().css('display', 'revert');
});
</script>
<?php
}
add_action('wp_head', 'add_script_to_head');

Related

Jetpack Sharing label how to customize it from functions

Hello Everyone,
I am trying to edit the Sharing label text of Jetpack plugin but having a problem to target specific text for example
in jetpack sharing settings there is an option with input field called
Sharing label
to add text before sharing icons. I have written there
Love it? Share it
here i want to add css style of italic and bold to
Share it
text but cannot do from text field as it not allow html tag. Is there any way i can target this specific share it text using css or function?
Here is piece of code btw with class assigned to that text
<h3 class="sd-title">Love it? Share it</h3>
you can replace text by using java script and set css.
add below function in function.php
function myscript() {
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
jQuery( '.sd-title' ).html("Love it? <span class='share_it'>Share it</span>");
} );
</script>
<?php
}
add_action( 'wp_footer', 'myscript' );

TinyMCE element out of place on custom WordPress page

I am creating a small custom test administrator page in WordPress and when I insert a wp_editor command the textarea was displayed on the top of the working area?
Unfortunately no CSS was able to restore it to its correct position. Any help or ideas will be greatly appreciated.
Edit: Thank you for your quick reply I am writing the very simple code below. As you can see it is nothing super, just a test:
function TstPlg_PageDisplay() {
$MyPage = '
<div class="wrap">
<h2>TestPlugin</h2>
<p>This is a test for the TestPlugin Page</p>
<hr>
<div>
'.wp_editor('','MyTextArea').'
</div>
</div>';
echo $MyPage;
}
function TstPlg_AddMenuPAge() {
add_menu_page( 'TstPlg_PageDisplay', 'Test Plugin', 'manage_options', 'TstPlg_PageDisplay', 'TstPlg_PageDisplay');
}
add_action ('admin_menu', 'TstPlg_AddMenuPAge');
It seems (it's hard without code), that the textarea is echoed and the plugin code is outputed directly.
To avoid this you can use ob_start(), ob_get_clean() and after echo the result (textarea) where you want.

Remove "p" tag from content generated by a WordPress plugin

I realize there are dozens of this type of question, but since I can't find in any of them the solution to this specific problem, it's unlikely a "This question has already been answered here" type addition will make much sense. And to anyone who's ever tried getting a real, specific, detailed answer on the WordPress.org forums, good luck!
I'm using the Store Locator Plus plugin. Had some back-end coding issues which I had to fix because getting the guy (or company) who wrote it to answer questions on his website forum is like pulling teeth (not that anybody who spends $300 on a plugin deserves support, but anyhoo...)
So, here is a chunk of code where I hard coded a submit button html. Then I worked with a custom style sheet, and the button actually does work and look nice. The problem is that on the html source, WordPress has sprinkled spurious <p> and </p> tags in the html I created.
For now, please don't dwell on how the button is made, which is a bit of a hack. There are reasons why I used a div tag within a button content, it's because without it the text in the straight button comes out really crappy, not vertically aligned correctly, can't control the font-family or font-size values. Those problems will be for another question, at another time.
Here is the function in the plugin where I created a custom button:
function create_DefaultSearchDiv_Submit() {
$this->slplus->debugMP('msg',__FUNCTION__);
if (get_option(SLPLUS_PREFIX.'_disable_search') == 0) {
// Find Button Is An Image
//
if ($this->slplus->settings->get_item('disable_find_image','0','_') === '0') {
$sl_theme_base=SLPLUS_UPLOADURL."/images";
$sl_theme_path=SLPLUS_UPLOADDIR."/images";
if (!file_exists($sl_theme_path."/search_button.png")) {
$sl_theme_base=SLPLUS_PLUGINURL."/images";
$sl_theme_path=SLPLUS_PLUGINDIR."/images";
}
$sub_img=$sl_theme_base."/search_button.png";
$mousedown=(file_exists($sl_theme_path."/search_button_down.png"))?
"onmousedown=\"this.src='$sl_theme_base/search_button_down.png'\" onmouseup=\"this.src='$sl_theme_base/search_button.png'\"" :
"";
$mouseover=(file_exists($sl_theme_path."/search_button_over.png"))?
"onmouseover=\"this.src='$sl_theme_base/search_button_over.png'\" onmouseout=\"this.src='$sl_theme_base/search_button.png'\"" :
"";
$button_style=(file_exists($sl_theme_path."/search_button.png"))?
"type='image' class='slp_ui_image_button' src='$sub_img' $mousedown $mouseover" :
"type='submit' class='slp_ui_button'";
// Find Button Image Is Disabled
//
} else {
$button_style = 'type="submit" class="slp_ui_button"';
}
// TODO: find_button_label get_option should move to Enhanced Search
$string = "<div id='radius_in_submit'><button type=\"submit\" id=\"addressSubmit\" class=\"slp_ui_button\"><div class=\"button-inner\" >Find A Store</div></button></div>";
return $string;
}
return '';
}
You can see that two or three lines from the bottom, just before the closing bracket of the function, I wrote a variable named $string with the string value being the html of the button, which is wrapped in a div with an id='radius_in_submit'.
Now, here is the html output of the button:
<div id='radius_in_submit'><button type="submit" id="addressSubmit" class="slp_ui_button"></p>
<div class="button-inner" >Find A Store</div>
<p></button></div>
</p>
</div>
You can see that the "p" tags totally don't belong there.
What have I tried...I have tried many variations on adding the remove_filter('the_content','wpautop'); in the theme's functions.php file, but that has never really worked for me on anything for some reason.
Here is the latest code I tried, inserted just before the closing ?> in my functions.php file:
function rm_wpautop($content) {
global $post;
// Remove the filter
remove_filter('the_content', 'wpautop');
return $content;
}
// Hook into the Plugin API
add_filter('the_content', 'rm_wpautop', 9);
...but it doesn't solve my problem. The button does work, I could leave it alone, but I can't stand those p tag insertions.
Development url where you can see it: store locator

WordPress / CF7 - Customising the Contact Form 7 ajax loader gif, depending on location

I am using the Contact Form 7 plugin on a web site, which has a contact form in the footer of every page and also a contact form in the main area of a dedicated Contact page.
I know how to customise the ajax loader gif in CF7...
function my_wpcf7_ajax_loader () {
return get_stylesheet_directory_uri() . '/images/my-loader-image.gif';
}
add_filter('wpcf7_ajax_loader', 'my_wpcf7_ajax_loader');
...but my problem is that I need to specify two different loader images - one for the footer form and one for the Contact page form. (The reason for this is because one form is on a white background and the other is on a red background, and despite experimenting with different loader gifs I don't think it is possible to have a loader gif that looks good on both.)
Here's the solution: https://gist.github.com/tctc91/8271205
add_filter('wpcf7_ajax_loader', 'my_wpcf7_ajax_loader');
function my_wpcf7_ajax_loader () {
return network_home_url() . '/assets/themes/ips-helpdesk/images/ajax-loader.gif';
}
As loading image is an img element with src attribute, css methods will not be helpful.
It would be required to change src attribute of img tag through JavaScript and without modifying the core js of contact 7 form plugin (to allow plugin upgrades in future), I have come with following JavaScript solution to apply this change by bruteforce method.
(function($) {
setInterval(function() {
if(typeof $.fn.wpcf7InitForm != "undefined") {
//Contact Form 7 is loaded and initialized
$loaderImage = $("#wpcf7-f52-o2 img.ajax-loader"); // modify your selector accordingly
if(!$loaderImage.data("pathChanged")) {
$loaderImage.attr("src", "ALTERNATIVE_IMAGE_PATH");
$loaderImage.data("pathChanged", true);
}
}
}, 2000);
})(jQuery);
Though it may not be the best way, See if it helps.
I read an article with a solid solution for your problem. They gave this solution:
// Change the URL to the ajax-loader image
function change_wpcf7_ajax_loader($content) {
if ( is_page('contact') ) {
$string = $content;
$pattern = '/(<img class="ajax-loader" style="visibility: hidden;" alt="ajax loader" src=")(.*)(" \/>)/i';
$replacement = "$1".get_template_directory_uri()."/images/ajax-loader.gif$3";
$content = preg_replace($pattern, $replacement, $string);
}
return $content;
}
add_filter( 'the_content', 'change_wpcf7_ajax_loader', 100 );
link to the article here:
Note: We're using a heavily modified twenty twenty theme and NONE of these solutions worked. Tried them all. Updated to latest version of plugin, still the same issue. Can't disabled plugins one at a time and test by practical means because there are dozens and because we need the ones that we have.

Make Wordpress Pages's Titles readonly

I'm looking for a WP function that add the Read-only parameter to all Pages's Titles's input, that will make the Page's title unalterable.
Thanks a lot in advance.
This can be accomplished with some simple JavaScript/jQuery. Create a file called admin_title_disable.js, and queue it up within functions.php. For example:
functions.php:
wp_register_script('admin_title_disable', '/path/to/admin_title_disable.js');
function disableAdminTitle () {
wp_enqueue_script('admin_title_disable');
}
add_action('admin_enqueue_scripts', 'disableAdminTitle');
Now, in your js file:
jQuery(document).ready(function ($) {
$('#title').attr('disabled','disabled');
});
This will set both post and page title input fields with a disabled attribute. Hope this helps!
If you want to restrict this script to a particular admin page, wrap the add_action hook in a conditional that compares $_GET['page']. You can also take advantage of the $hook parameter that is available when using admin_enqueue_scripts to check for the page. See here.
Update::
WordPress makes it a little tricky to tell between post and page edit screens, but there is a hidden input that you can take advantage of. :) Here's an updated version of the jQuery that will only run on page edit screens:
jQuery(document).ready(function ($) {
//find the hidden post type input, and grab the value
if($('#post_type').val() === 'page'){
$('#title').attr('disabled','disabled');
}
});
No need to make a seperate js file. Adding this to your function.php will do the same that Matthew showed.
function admin_footer_hook(){
?>
<script type="text/javascript">
if(jQuery('#post_type').val() === 'post'){
jQuery('#title').prop('disabled', true);
}
</script>
<?php
}
add_action( 'admin_footer-post.php', 'admin_footer_hook' );
This Solution Will disable clicking on the post title and editing it using CSS. CSS targets post type "page" only. It has been tested on Gutenberg visual editor. Users Can still edit title from "Quick Edit".
Add this code to your functions.php file.
function disable_title_edit() {
if(!current_user_can('administrator')){
if( !current_user_can('administrator')){ ////Only allow Admin
echo '<style>.post-type-page .edit-post-visual-editor__post-title-wrapper{
pointer-events: none;
}</style>'; } }
}
add_action('admin_head', 'disable_title_edit', 100);

Resources