Highlight very simple code tag in wordpress? - wordpress

In a self hosted wordpress blog, I'm trying to hightlight this code : [xml], inline.
If I put this :
[code language="ps" light="true"][xml][/code]
It outputs as 1
Which html source is :
<div class="line number1 index0 alt2">
<code class="powershell plain">1</code>
</div>
How can I tell the syntaxt highlight engine to ignore the [xml] tag and render it as is?
Is it possible to hightlight some words in a sentence? (like the ``code`` construct in SO)
[edit] I also tried :
[code language="ps" light="true"][xml][/code]
But it outputs [xml]

Use this plugin to highlight code snippets
https://wordpress.org/plugins/crayon-syntax-highlighter/

Related

Set custom initial page in blogdown

Is it possible to set the initial page in blogdown? Instead of the default one that shows the posts I would like to have a custom one. I want to have my own index.html (the root one).
Thanks.
Assuming you are using Lithium - A simple responsive Hugo theme, one possible way to do this is the following.
1] Copy layouts/_default/list.html to a new layout file named layouts/_default/home.html
2] Edit layouts/_default/home.html so it contains this:
{{ partial "header.html" . }}
<main class="content" role="main">
<h1>
My heading
</h1>
<p>
My paragraph
</p>
</main>
{{ partial "footer.html" . }}
Your home page will now contain "My heading" and "My paragraph," along with the Lithium header and footer. If you do not want to use the Lithium header and/or footer, remove those partial calls from home.html.[*] There's a lot more that you can do with Hugo layout files, which you can learn about in my Hugo tutorial in the section 15. Explore the layouts directory and at gohugo.io's Category: templates.
I hope this is enough to get you started with Hugo layout files.
[*] If you remove the header partial, you need to put something like <!doctype html><title>a</title> at the top. More about this is in What's a valid HTML5 document? - Stack Overflow

how do i locate files in wordpress by inspecting element a particular element in google chrome?

I want to change some particular line on my Wordpress site which I cannot change in the customization. How do I locate a certain line with inspect element in chrome?
My website is www.Artiana.io and I want to edit this line:
"<h5 class="subscribe-description">Learn more</h5>"
Please, can anyone help me out?
Let me show you how you can use WordPress's hints in html body class to find the php file:
WordPress gives hint in the HTML's body tag that which particular template was used to display this page.
In your case we have following classes in the body tag:
<body class="home page-template page-template-page-templates page-template-page_front-page page-template-page-templatespage_front-page-php page page-id-466 custom-background wp-custom-logo blog-post">
Now there is a specific class which ends with php, which tells that template was used by your theme to build this page. i.e. page-template-page-templatespage_front-page-php
Now it could mean that in your theme folder:
/wp-content/themes/hestia/
There could be sub folder or folders called: **page-template/page-templates** and inside it is page_front-page.php PHP file, which is being used to create this layout. See if you can locate the code you are trying to modify there.

Link to archive post type on the specific post

I have this code in the loop on my post :
<div class="retour">Projets</div>
When it goes to the post_type_archive page, I'd like my browser to go directly on the specific post.
Can I add an anchor tag to my function ?
How can I manage that ?
Thank you !
Just add an anchor tag to the end like this:
<div class="retour">Projets</div>

WordPress Editor Image for Shortcode

Quick question about WordPress. I've been Googling all over the place and cannot find an answer.
Basically I'm looking to replicate what happens when you add a gallery: have an image displayed as a stand in for the gallery shortcode [gallery]. The shortcode's visible when you go to edit HTML.
I'd like to exactly copy this effect: When a shortcode inserted into the editor I'd like for to to be rendered as an image.
Things I've Tried:
Inserting an element (image, div, I found an input is pretty unfuckwithable, etc) that's wrapped by a shortcode (This works ok, not great. The short code's still visible and WP will auto add paragraphs to the element to create space that users could, possibly, add content that'll be eaten by the short code) -
Inerting the short code as a < !-- --> comment (This also doesn't work great, WP will occassionally eat it moving between Visual/HTML. The comments ALSO eat your content < !-- [shortcode]--> placeholder < !--[/shortcode] --> = < !-- rendered shortcode -->)
That's the extent that I've thought of things. I cannot find a guide on how to do mimic the [gallery]'s behavior and can't find it by going through wp-admin's guts.
Thanks!
Alright, found the answer thanks to Dan's hint. Here's how to do it:
First (as Dan suggested) take a look at how they add the Gallery plugin to Tiny MCE. There's actually an uncompressed js file that will give you the overview you need, find it in:
/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.dev.js
This goes over the basics on adding this type of plugin to TinyMCE (more info here). To get WP to load the .js file with your TinyMCE plugin, see this helpful guide.
Basically here's the code:
if ( get_user_option('rich_editing') == 'true') {
add_filter("mce_external_plugins", "add_jolokia_tinymce_plugin");
//Applying the filter if you're using the rich text editor
}
function add_jolokia_tinymce_plugin($plugin_array) {
$plugin_array['example'] = '/path/to/example.js';
return $plugin_array;
}
Add this to a plugin or function.php in a theme And you're good!

Views is stripping tags from the output

I have a Drupal view which should output a video player using flash. I am trying to output a script that will call the flash film. The problem is that Views applies some sort of filter that strips my <script> tags, the opening and the closing one. I am searching a solution (some setting in views that will disable that filter), but cannot seem to find an answer. Other HTML tags work, but it seems the script tag is being stripped, probably for some security reason.
I have selected the option to rewrite the output of the field and I am using the tags correctly
Views also strips style attributes from my tags. For example:
<h3 style="border-bottom: solid 1px #ffcc99;">Some text here</h3>
appears like this:
<h3>Some text here</h3>
Is there a solution for this? Thank you.
Begin edited
I am pasting below the code I am using in my view.
<div class="bloco-filme">
[title]
<div class="field-imagem">
[field_imagem_fid]
<script type='text/javascript' src='sites/default/files/js/swfobject.js'></script>
<div id='mediaspace[nid]'>Se você estiver visualizando esta mensagem, significa o Flash Player não está instalado em sua máquina. Para assistir ao vídeo é preciso instalar o Flash player</div>
<script type='text/javascript'>
var so = new SWFObject('sites/default/files/plugins/jqplayer/player.swf','mpl','205','undefined','9');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addParam('wmode','transparent');
so.addVariable('file','[field_video_fid]');
so.addVariable('quality','false');
so.write('mediaspace[nid]');
</script>
[field_video_fid]
</div>
<div class="field-resumo">
<p>[body]</p>
</div>
</div>
Edited again
The code above is beinng posted in my view. I have created a view to handle this. This is the FIELDS area of my view:
Fields
Node: Nid
Node: Título (title, it is in pt-br)
Node: Link "editar" (edit)
Node: Link "apagar" (delete)
Conteúdo: Imagem thumbnail image
Conteúdo: Video URL do arquivo (video file URL)
Node: Corpo (Body)
I have disabled the display of all the fields above and have packed all the code in the Body field. There I selected the option that I want to rewrite the output of the field.
kiamlaluno identified the basic problem, but to solve it, you're going to have to use a field template which will avoid using the filtering system Views uses. Group 42 has a great guide to walk you through the basics of Views theming, so I'll just gloss over those details and talk about your specific case.
First, you need to identify which field you want to rewrite: I believe you're doing that using the Field configuration, but it's not clear which field you are rewriting. I'm going to assume it's the body field. Go through Group 42's guide to create a new template file for the body field in your theme.
In the new template file, use the following code:
<div class="bloco-filme">
<?php print $view->field['title']->render($row) ?>
<div class="field-imagem">
<?php print $view->field['field_imagem_fid']->render($row) ?>
<script type='text/javascript' src='sites/default/files/js/swfobject.js'></script>
<div id="mediaspace<?php print $view->field['nid']->render($row) ?>">Se você estiver visualizando esta mensagem, significa o Flash Player não está instalado em sua máquina. Para assistir ao vídeo é preciso instalar o Flash player</div>
<script type='text/javascript'>
var so = new SWFObject('sites/default/files/plugins/jqplayer/player.swf','mpl','205','undefined','9');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addParam('wmode','transparent');
so.addVariable('file','<?php print $view->field["field_video_fid"]->render($row) ?>');
so.addVariable('quality','false');
so.write('mediaspace<?php print $view->field["nid"]->render($row) ?>');
</script>
<?php print $view->field['field_video_fid']->render($row) ?>
</div>
<div class="field-resumo">
<p><?php print $output ?></p>
</div>
</div>
Save your new template file, and now the body field will be replaced with the correct output. Just make sure all the fields you've referenced in the template are before the body field within the Fields list when you edit the View.
You can see that this is mostly HTML with a few PHP bits. Code like this:
<?php print $view->field['title']->render($row) ?>
outputs the contents of a field other than current one (i.e. you use this code when you want to reference fields other than Body). It references the same row and finds the value of the field.
And code like this:
<?php print $output ?>
Outputs the value of the current field, in this case, Body.
I don't think the view is causing the issue. kiamlaluno is quite correct that the input format will strip a lot out of your code, unless you alter the input format, however I'm not sure you'll actually be able to achieve what you are trying to do using the body field in any sort of graceful way.
Use views to output the content you need from each node type, but I never use views to determine how this will be displayed (apart from ordering fields etc). I tend to do this either using the display fields option (/admin/content/node-type/[your-node-type]/display) or in the theme. In other words I theme the node (content type) or the field itself.
I would consider looking here - http://drupal.org/node/206980 - to see how to theme individual fields. use the field_ (field name prefix) at the start of a copy of the content-field.tpl.php in your theme folder (you'll find it in the theme folder of your cck folder), and use this to theme the field the way you want it to be presented (using your code above). So, when the view picks it up to display it, it will theme it using your code above.
This, of course, has the added advantage that you don't need to add in any code to the body element of the page, which is not a scalable way to do this at all.
Alternatively, you could write a small module which uses hook_field() (link 1, link 2) to rewrite the field display, but unless you want to be able to customize any of this in the admin area of the site, your best option is probably to theme the field itself as above.
I had nearly exactly this issue (thanks for posting it!), but a few things have changed (obviously) in the three years since this post.
In my case, using Views 3 and D7, I was able to paste all of the relevant swfobject code into a Header or Footer of my view, making sure to use the Text Area type with Full HTML as the text input filter.
No editing of the template.php was necessary. I even used token replacement to provide contextual filter arguments to my movie's flashvars.

Resources