Wordpress syntax highlighting - wordpress

I recently switched my blog from joomla to wordpress and i'm having problems when posting code snippets.
The editor seems to remove some of the characters when i save my posts.
I am using a plugin that i got from this link: http://alexgorbatchev.com/SyntaxHighlighter/
Example:
<pre class="brush: javascript">;
var window.onload = function() {
alert("Loading is complete");
};
</pre>
Is formatted to:
<pre>;
var window.onload = function() {
alert("Loading is complete");
};
</pre>
How can i solve this problem?

If you're on WordPress.com, I believe you should be using a shortcode like so: http://en.support.wordpress.com/code/posting-source-code/
If you're on self-hosted WordPress and using the WordPress plugin Syntax Highlighter (http://wordpress.org/extend/plugins/syntax-highlighter/), again I think the correct way to insert code is by wrapping it in a shortcode. So instead of < pre > you would use:
[javascript]
// your code here
[/javascript]
If neither of these sounds like an ideal solution (or works) there are a bunch of other syntax highlighter plugins for self-hosted WordPress that might be better: http://wordpress.org/extend/plugins/search.php?q=syntax+highlighter
Hope this helps - best of luck!

Agree with #Michelle.
This actually works for me.
[sourcecode language='javascript']
//Replace 'javascript' by the corresponding language
//Your code goes here
[/sourcecode]
It will work on save or update for hosted and non hosted sites.
Example.
To apply it to your text, you just have to switch to the 'Text' visual editor.

Your pages will load faster if you do the syntax highlighting before posting, using pygmentize: http://permafrostcodingstudio.com/articles/syntax-highlighting-in-posts/
It's a little more complicated, but worth being able to disable a plugin. Wordpress will run faster and be more secure with fewer plugins installed.

Related

How can I un-enqueue a javascript file in WordPress?

I'm working with Wordpress site and a script that I have to have is breaking a plugin that I also have to have lol.
What would be the best way to have that script not run when I'm on pages that use the plugin? Every page that has the plugin has "?fl_builder" on the end of the URL
I was thinking maybe use jQuery to have the script not run if the url contains "?fl_builder"? I'm just not sure how to write it.
Any help is appreciated!
Have you tried added a $_GET variable where you call your script?
Example:
if(isset($_GET['fl_builder'])) { wp_register_script(...); }

Showing scss file types in the Wordpress Admin UI

I am trying to show scss files in the WordPress admin UI, so I can edit them from there, like you do with PHP, CSS, or JS files. I have come across this filter, but it doesn't seem to work. I am running WordPress 4.9
add_filter('wp_theme_editor_filetypes', function ($types) {
$types[] = 'scss';
return $types;
});
Does anyone know why this would not function as expected?
UPDATE: This worked fine.... it was a cache issue I think. Just didn't show up right away for me.

Drupal 8 Preview button not working

When using a custom front-end theme, the preview button for my content stops working. It just redirects to the content overview page.
Am I missing something in my theme that allows me to use the 'preview' function?
You most likely have the ?destination=admin/content in your URL. This is a core bug. The current discussion can be read at:
https://www.drupal.org/node/2325463
Jason Ruyle's answer is correct, I had the same problem and solved it by adding this code to my module:
use Drupal\Core\Entity\EntityInterface;
function my_module_entity_operation_alter(array &$operations, EntityInterface $entity) {
if (isset($operations['edit']['query'])) {
unset($operations['edit']['query']['destination']);
}
return $operations;
}
The code could also be improved to target the right entities, if needed.

ckeditor load html code in the editor asp.net

I am trying to load html file in CKEditor in asp.net but for some reason I don't know how to put the html code from the code behind file.
CKEditor1.FilebrowserBrowseUrl = url;
CKEditor1.BasePath = url;
CKEditor1.Text = content;
none of that helped
Any advice? Thanks in advance, Laziale
I'm not sure which version you are using, but let's suppose that it's 3.x. I was playing around with the control and didn't find any possible way of doing this from code behind. However, I managed to make it work like this:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "fckInitialization", #"
window.onload = function () {
var oEditor = CKEDITOR.instances['" + txtPost.ClientID + #"'];
oEditor.insertHtml('<strong>This is a bold text.</strong>');
};
", true);
I tried it in IE 8 and the last version of Mozilla (I think it was 9) and it worked. I also tried the same thing, but instead of window.onload I used the jQuery $(document).ready() and it worked only in IE. The reason is that you have to wait for everything to load in order to use the functions from the CKEditor API. I played with Firebug and the insertHTML worked.
If you are using 2.x, you can see somewhere in Google the same approach, but with a different API. I just can't find the link right now.
Another problem will be here, as you may figure out, that if you want to initialize a long text, you will have to write everything in a script, which is not really nice.
Maybe a possible solution for you will be to convert the HTML to BBCode first and then just set the Text property. This, of course, depends on the way you use the control, because BBCode does not contain all possible tags, but you can always modify the bbcode plugin of CKEditor to meet your needs. And I tested it and it works.
PS. Probably you can do it with the JavaScript method and an AJAX call.
Hope this helps!
Assuming ckeditor is being initialized from a textarea field, you can simply populate the body of the textarea.

How does one inject variables into page templates from a custom Drupal module?

We've created a custom module for organizing and publishing our newsletter content.
The issue I'm running into now -- and I'm new to theming and Drupal module development, so it could just be a knowledge issue as opposed to a Drupal issue -- is how to get each newsletter themed.
At this point the URL structure of our newsletter will be:
/newsletters/{newsletter-name}/{edition-name}/{issue-date} which means that we can create template files in our theme using filenames like page-newsletters-{newsletter-name}-{edition-name}.tpl.php, which is great. The one issue I'm running into is that all of the content comes through in the $content variable of the theme. I'd like to have it come through as different variables (so that I can, inside the theme, place certain content in certain areas.)
Is there a proper way for doing this?
Edit: To answer some questions: The issue is a node (there are issue, edition and newsletter nodes) and the path is being set using hook_menu with wildcards and a router.
The best answer I could find was to add a check inside of phptemplate_preprocess_page to send the vars back to the module and have them be updated.
Like so:
function phptemplate_preprocess_page(&$vars) {
if (module_exists('test_module')) {
_test_module_injector($vars);
}
}
then in my test_module.module file I created this function:
function _test_module_injector(&$vars) {
$vars[] = call_to_other_functions_to_load_vars();
}
It seemed to work. I wish there was a way to do this without having to touch the theme's template.php file, but otherwise this works well.
If there were better documentation for template preprocess functions, Drupal would be a lot more accessible - as it is, you need to piece together the information from a lot of different explanations. One place to start is here:
http://drupal.org/node/223430
but if you take the time to work through the tutorial below, you'll find you can do most things:
http://11heavens.com/theming-the-contact-form-in-Drupal-6
This is an old post, and the OP's issues seems to have been solved.
However, just for others finding this through Google (or otherwise):
Install the 'Devel' module: http://drupal.org/project/devel
Also the 'Devel Themer' module: http://drupal.org/project/devel_themer
Use Devel Themer to go through the $content variable and find what you need to pull out.
There are a bunch of Devel/Themer docs/tuts out there, but its usage is pretty straightforward. Note, though, that some stuff in there will need to be sanitized before printing in the theme.
The suggestion to show the node as a View and then modifying the view templates sounds pretty crazy, though it'll work.

Resources