So here i find myself, again, struggling with wordpress wysiwyg editor.
a client of mine requested to migrate his website to WP. No probs, a breeze :).
Really was easy, migrated from one DB structure to the other, and everything went OK.
Now I have a problem. The old site, used an editor that added <br> and <p> tags to the content in order to format it (sounds legit to me). But wordpress will not allow these tags. whenever the client tries to edit a post, WP removes all the HTML tags it considers "illegal".
So I went on the search. First I tried to install some recommended plugins I found for this problem (such as this one). Didn't work at all for me (for some others it did i believe)...
Then I found a post that told me to add a function to the function.php file which will remove the filters :
function mod_mce($initArray) {
$initArray['verify_html'] = false;
return $initArray;
}
add_filter('tiny_mce_before_init', 'mod_mce');
and also this:
function my_tinymce( $init ) {
$ext = 'div[id|name|class|style]';
if ( isset( $init['extended_valid_elements'] ) ) {
$init['extended_valid_elements'] .= ',' . $ext;
} else {
$init['extended_valid_elements'] = $ext;
}
return $init;
}
add_filter( 'tiny_mce_before_init', 'my_tinymce' );
functions from this thread.
Nope, didn't work also...
Someone - any idea? It seems so silly, but there is so much debate around this subject...
Thanks
You may try this to remove filters that wpautop uses to filter content and excerpt, just put these in your funcions.php file
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
Reference: WordPess wpautop
To allow older content with p and br to load in tinyMCE
function my_tinymce_config( $init ) {
$init['remove_linebreaks'] = false;
$init['convert_newlines_to_brs'] = true;
$init['remove_redundant_brs'] = false;
return $init;
}
add_filter('tiny_mce_before_init', 'my_tinymce_config');
Reference: tinyMCE Configuration look at Cleanup/Output and try playing with these.
Another way could be helpful Reference
tinyMCE.init({
...
verify_html : false
});
Related
I load wordpress with my php code like this to do actions:
define( 'WP_USE_THEMES', false ); // Don't load theme support functionality
require( './wp-load.php' );
How could I also disable plugins temporarily when I want to add posts, etc? This would be to use less server resources...
I don't believe there's actually a good way to do this. The best way is probably to run your function before plugins are loaded. Otherwise you're looking at programatically renaming the /plugins folder or WP_PLUGIN_[DIR/URL] constants which just screams "error prone"
Effectively you can hook into the first action hook available, which is muplugins_loaded: Source. Especially if you have no mu-plugins to be run, it should be run almost instantaneously:
add_action( 'muplugins_loaded', 'run_before_plugins_load' );
function run_before_plugins_load(){
if( condition == met ){
// Insert your post here
if( $post_id = wp_insert_post( $my_post ) ){
exit(); // Post inserted, stop processing anything.
} else {
wp_die( 'Post not inserted' );
}
}
}
From there you'll have inserted a post and stopped any further propagation. Of course, you can replace exit and wp_die with whatever you want - it's just the fastest way I can see to run a WP function without actually loading plugins.
I can use bp_get_activity_content_body() on entry.php
but how can i use it on bp-core-template.php
Sorry for my poor question, i’m very new for php editor.
bp-core-template.php is one of the core files of BuddyPress and that makes it a bad idea to edit the file. Whenever you update Buddypress there is a good chance your changes will be overwritten.
If you are trying to alter the result of a function found in bp-core-template.php then you will want to use one of the filters in that function to safely alter the content "the wordpress way".
So if you want to change the output of the function bp_create_excerpt found on line 877 of bp-core-template.php you could use the filter bp_create_excerpt in the functions.php file of your theme.
In functions.php (example modified from hookr.io):
// define the bp_create_excerpt callback
function filter_bp_create_excerpt( $text, $original_text, $length, $options ) {
if ( function_exists( bp_get_activity_content_body )
$text = bp_get_activity_content_body();
return $text;
};
// add the filter
add_filter( 'bp_create_excerpt', 'filter_bp_create_excerpt', 10, 4 );
EDIT: It should be noted that I do not know what bp_get_activity_content_body() will return in this context and I would probably just return $original_text if I didn't want a truncated excerpt. My intent is to highlight how you should be changing output of things from a plugin's core files.
I'm trying to build my first Wordpress plugin and it's giving me a ~LOT~ of grief.
I've got a plugin template I'm using, and I'm following THIS tutorial to turn it into something I can use.
The tutorial says to put a function in [insert plugin name]-admin.php to make 'settings' appear near the plugin on the plugins.php page.
This is what it's supposed to look like:
(source: scotch.io)
The thing is, I have tried inserting the function and I just can't get this 'settings' link to appear.
The code the tutorial says to use is this:
public function add_action_links( $links ) {
$settings_link = array( '' . __('Settings', $this->plugin_name) . '', );
return array_merge( $settings_link, $links );
}
I've tried using this--and similar snippets that I've found on other sites after googling--and none of them work. I know that page= is supposed to link to the page URL, I'm not entirely sure what mine is (is it the plugin slug?). Anyway, I'm currently using the plugin slug after 'page='
If anybody here could help me out with this, it would be greatly appreciated. I know the tutorial I'm using was sloppily written because I have managed to find mistakes in it that were causing errors, and I'm relatively new to PHP and totally new to Wordpress plugins.
Did you also add the beloning add_filter?
Like here:
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'my_plugin_action_links' );
function my_plugin_action_links( $links ) {
$links[] = 'Settings';
$links[] = 'More plugins by WP-Buddy';
return $links;
}
Also see:
https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
This is my first post here, so I apologize in advance for any mishaps.
I've been searching for hours trying to figure this one out, but I simply can't seem to understand why this is happening.
The site I'm setting up is a child site (not in a multisite sense, but as a separate site/domain with the same branding). Some of the posts on my site will originate from the parent/main site (but will be made as new posts through copy-paste), and I want the original article ID as part of the permalinks.
E.g. http://www.example.com/hello-world/12345/, where 12345 is the article ID of the article on the parent/main site.
To accomplish this, I've added a custom field to my posts where I can add the article ID of the original article with external_article_id as Field Name. I've then tried to manipulate the permalinks with the following code:
add_filter('post_link', 'append_custom_permalink', 10, 2);
function append_custom_permalink($url, $post) {
$newurl = $url;
if ($post->post_type == 'post') {
$custom = get_post_custom_values('external_article_id', $post->ID);
if (!empty($custom))
$newurl = $url . $custom[0] . '/';
}
return $newurl;
}
Whenever I output the permalink to the posts it appears exactly as I want it, both in the editor and on the site. However, when I either click a link or enter the address manually, I get redirected automatically to http://www.example.com/hello-world/12345/12345/. It duplicates the additional numerical slug, and also happens when I replace $custom[0] with a hard-coded numeric value. This applies to all posts, and my permalink structure (in the settings) is set to /%postname%/.
I even tried setting the permalink structure to /%postname%/%ext_article_id%/ and replace %ext_article_id% with $custom[0], but with the exact same outcome. I also tried using the same code on another WordPress site, except this time with pages instead of posts, also with the exact same outcome.
Ideally I would like to use something like add_query_arg($custom[0], '', get_permalink($post->ID));, but omit the question mark that comes along with it.
Could someone please explain to me why this is happening, and how I can circumvent this? Do I need to use some other filter, or how can I approach this?
Thank you in advance!
In order to make this work you also need to make WordPress aware of the rewrite_tag and specify an additional permalink structure via add_permastruct. The following code should do the trick:
function append_custom_permalink( $post_link, $post ) {
if( $post->post_type == 'post' ) {
$custom = get_post_custom_values( 'external_article_id', $post->ID );
if( ! empty($custom) ) {
$post_link = $post_link.$custom[0].'/';
}
}
return $post_link;
}
add_filter('post_link', 'append_custom_permalink', 10, 2);
function sof_30058470_posts_rewrite() {
add_rewrite_tag('%external_article_id%', '([^/]+)', 'external_article_id=');
add_permastruct('external_article_id', '/%year%/%monthnum%/%day%/%postname%/%external_article_id%/', false);
}
add_action('init', 'sof_30058470_posts_rewrite', 10, 0);
Make sure to re-save your permalink structure at Settings->Permalinks once you added the code. You may also need to refresh/clear your browser cache.
I have a WordPress site that has a standard Page called Places with URL
example.com/places/
And I have several child Pages called by cities
example.com/places/city-1
example.com/places/city-2
Now, I have a custom post type Place that should indicate a single place and should have permalink like
example.com/places/place-1
But then if I go to one of the previous links with city-1, city-2 I get 404 obviously because there is no place with that permalink.
Is there a way for WordPress to drop to previous permalink. So if there is no place with that name, look for a page with it.
You could probably use the the REFERER-value from the PHP server variable $_SERVER, but it´s not very reliable and can be altered.
I am using the plugin "Permalink Finder" in one of the pages I am maintaining and that works quite well for finding changed URL. You could give it a try and see if it works for you, too.
In case somebody ever having a similar problem, it can be done by using verbose page rules. This is an example I found at WordPress Stack Exchange
https://wordpress.stackexchange.com/questions/22438/how-to-make-pages-slug-have-priority-over-any-other-taxonomies-like-custom-post
add_action( 'init', 'wpse16902_init' );
function wpse16902_init() {
$GLOBALS['wp_rewrite']->use_verbose_page_rules = true;
}
add_filter( 'page_rewrite_rules', 'wpse16902_collect_page_rewrite_rules' );
function wpse16902_collect_page_rewrite_rules( $page_rewrite_rules )
{
$GLOBALS['wpse16902_page_rewrite_rules'] = $page_rewrite_rules;
return array();
}
add_filter( 'rewrite_rules_array', 'wspe16902_prepend_page_rewrite_rules' );
function wspe16902_prepend_page_rewrite_rules( $rewrite_rules )
{
return $GLOBALS['wpse16902_page_rewrite_rules'] + $rewrite_rules;
}