PHP code inside WP molecule - wordpress

I need to add a PHP snippet inside a molecule in WP. WP Editor allows to insert <code> </code>
but even if I wrap PHP with that it does not seem to help.
All I want it to insert the current year, so I'm OK with either PHP or JS or whatever else WP supports.
Anyone had experience with that?

There are two plugins that come to mind. One is wp-syntax http://wordpress.org/extend/plugins/wp-syntax/, a rich code display plugin with many features. You'll have to switch to code editing view to insert your <code> or <pre> tag with the PHP snippet.
The other one is a low tech homebrew of mine, "include custom field": http://pp19dd.com/wordpress-plugin-include-custom-field/
The homebrew is a shortcode plugin that lets you place arbitrary code or data inside a custom field, and then inject it into the post with something like [include mycode1]. Note that it'll be up to you to encode it to where it can be shown, or modify it to where it acts like a code highlighter (can be done easily with highlight_string.)
Reason I like my brew version is because it a) separates a blog post from the code, and b) survives numerous editing cycles and/or imports. All other inline solutions annoy me to no end.

Related

Where could be inline-css in Wordpress

I am working on this webpage:http://hypoinvest.sk/ which runs on Wordpress with this theme If you check source code you can see a lot of inline-css and I want to know in which files are actually defined. Only thing what I know about it they are called by function wp_head() in header.php. I have local copy of all files on this web and I can't find any mention about some of that css rules through unix grep. Anyone suspect where these css rules could be located?
check site and let me know.
Run a search in the source code for
style-inline
As this appears to be the 'handle' designated as the first variable in the function wp_add_inline_style. The "-css" is added automatically. You'll see this on line 79 of the page source.
https://codex.wordpress.org/Function_Reference/wp_add_inline_style
You want to check your page back-end site where you put content ,
I think are you using any compose or editor to create page on edit page.
check it edit option it has some inline css.

WordPress - highlighting mixed code in the materials published through the admin panel (php + css + html + js)

Good afternoon. Is there a solution that allows you to frame the piece of code in several languages, and highlight it. Tried several plugins - no one helped.
Note also that wordpress is crazy if tags
<? php / * random code * /?>
found in the text.
The only plugin that handles more or less, but not highlighted as it should - WP-Syntax It is possible to specify the language in the attributes of the tag, eg
<pre lang = "php">
But first when inserting the code necessary to embed a lot of pre-tags you can be confusing, and secondly it each tag is separated from the rest of the code and is very torn strange display of code.
Trying to embed complex code in a standard Wordpress editor window is an exercise in frustration. TinyMCE, the Wordpress editor, is configured to strip any unsafe tags from your code. You can customize TinyMCE to behave how you want it to, but I think that is less than optimal.
A better solution would be to use a plugin like Advanced Custom Fields or build a Custom Post Type to add some plaintext fields with a language selector for styling your code.

How to make sure changes to a Wordpress plugin won't be lost on plugin update?

I'm pretty sure I've read somewhere that you can actually move the main plugin *.php file to somewhere else (I assume under your theme directory) to have it safe in case you made changes to it and your plugin updates. I tried Google but I can't find anything. Google page with good results will suffice.
I've just experienced a situation where my 2 plugins which had its layout changed and accommodated my needs and I want to make sure it doesn't happen again. Apart from having the main file in another location, is there a way to move along any CSS and JS files as well?
In Concrete5 CMS there is a nice way of doing this, by creating a new folder inside a block of an addon (may be regarded as a WP plugin), inside of which you can create copies of main file, any CSS and JS files and then you can simply edit them and choose that template for a page location you are using that block in.
I assume there is no such thing in Wordpress but how close can I get?
UPDATE: I found where I applied that advice on creating a new instance of the file then moving it to the theme directory.
The plugin in question was HL-Twitter. These are the plugin files:
admin.php
archive.php
functions.php
hl_twitter.php
hl_twitter_archive.php
hl_twitter_widget.php
import.php
widget.php
Now, this is the top contents (commented out) of the hl_twitter_widget.php:
Widget Theme for HL Twitter
To change this theme, copy hl_twitter_widget.php
to your current theme folder, do not edit this
file directly.
Available Properties:
$before_widget
$after_widget
$before_title
$after_title
$widget_title
$show_avatars
$show_powered_by
$num_tweets: how many tweets to show
$tweets: array of $tweet
$tweet: object representing a tweet
$tweet->twitter_tweet_id
$tweet->tweet
$tweet->lat
$tweet->lon
$tweet->created
$tweet->reply_tweet_id
$tweet->reply_screen_name
$tweet->source
$tweet->screen_name
$tweet->name
$tweet->avatar
$user: represents the Twitter user (ONLY SET IF SHOWING A SINGLE USERS TWEETS!)
$user->twitter_user_id
$user->screen_name
$user->name
$user->num_friends
$user->num_followers
$user->num_tweets
$user->registered
$user->url
$user->description
$user->location
$user->avatar
So I was wrong about copying the main file (in this case hl_twitter.php), but still - this enabled me to edit the file outside the plugin directory and the system somehow checks for its existence and picks it up if exists.
If this behavior something that is natively supported by Wordpress or it has been integrated in the plugin itself?
With themes, Wordpress has a concept of "child themes" which allows exactly that: to keep changes separate from main theme, in case it changes.
I haven't yet found a way to do this with plugins.
I'm using a few tactics myself:
I bump plugin version to a very high number like 99.9. This way Wordpress won't ever update the plugin.
Store my plugins in version control (i use git, but it doesnt matter), this allows you to update the plugin, run the 'diff' tool and see what changes happend. If you don't like you just revert like it would be a bad code you've written. But this approach requires a bit of skill.
Are you talking about running parts of a modified 3rd party plugin, and an updated version, at the same time?
That's not going to be possible. There is no magical method of "preserve my changes and transfer them into the new version automatically". The way to go here is doing a diff between the edited version and the update, and integrating the changes in the actual source files.
The bottom line is, if you manually edit a third party plugin, you're in for manual review (and possibly rework) once an update takes place. That's why it's usually not a good idea to extensively modify third party plugins.
Well in fact, yes! There is some kind of way.
You have to remove the to be modificated plugin's original actions/filters and then add your altereted actions/filters.
If the desired plugin is even coded in OOP you can just inherit the whole class and rewrite the wanted functions (oh sorry: "methods". we're talking about OOP ;) ). Instantiate your inherited class and rest as above.
Maybe there are better ways! I already search for a method so that the original class won't even get loaded but our altered one instead but I'm no John Carmack.

Hide right-sidebar on specific node/module

I am setting up my first drupal (6) site and so far I like the system.
I've now run into a problem however: to give the content more space I want to hide the right-sidebar (with the navigation menu etc.) on every page from a specific module (or also fine: for a specific node/view from the module)
The only way I've come up with is to add some CSS to the module CSS files, but this doesn't seem very clean to me since I would need to redo it on every update (also the module uses 5 CSS files for different views)
Is there a better way to do it?
To be clear: I don't want to just hide a block, I want to hide the whole sidebar
Hmmm. Is this a custom module or something commonly available? Some modules allow you to create custom tpl.php files (see the theming guide) for them. This might quickly solve your problem.
If you are theming a node, then it is significantly easier. You can theme a specific type of node by naming convention (again via .tpl.php files in your theme). You can check out how to do that here.
Definitely check out the theming guide, since you will probably want to create your own theme instead of hacking on one of the core themes (not recommended). Typically you can copy /themes/garland into /sites/all/themes/my_garland, switch your site's theme to that and then make whatever changes you need (otherwise you'll have to reapply changes every time you update core).
Finally, you can check for path arguments (which seemed weird to me at first) if you want to do things in PHP that are more complex (see the arg function). If this is your first Drupal site, you may also need to know how to include css programatically.
Good luck! Drupal is a fun and interesting product.
You can configure the block visibility for each individual block and path in your website (admin/build/block). Under 'Configure'/'Page specific visibility settings'/'Show block on specific pages' you can set the navigation menu block not to be displayed for some specific routes. If a sidebar has no blocks to display it will hide itself allowing more space for the content.
You could use the Context module, with it you can, among other things, set rules for each block/menu where and when i should be shown (or not). You could also do this the way Josep explained but with Context you get more options.
And as Josep said when there are no blocks active in the sidebar it should disappear automatically, if not check your page.tpl.php it should have something like this in it:
<?php if ($right): ?>
<div id="sidebar-right">
<div id="sidebar-right-inner"> <?php print $right; ?> </div>
</div>
<?php endif; ?>
So if there is nothing in the Right region it doesn't display the sidebar. Maybe you have to change the name of the region, depending how they are called in you template.
I believe you already got the answer or a way to fix your problem.
There is a simple way to fix your problem. Here's a link.

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