Wordpress : hide shortcodes in TinyMCE - php

Is it possible to change shortcode appearance in Wordpress TinyMCE editor? One of my clients has no HTML knowledge and it's really hard to explain him what not to edit on subpages.
All I want is to hide the shortcodes and add a button on the kitchen sink to show them.
Work arounds.
1 - Filter content before displaying in the editor. Onclick of the button in kitchen sink, call the same url with a $_GET param e.g ?filter=false and do not filter the content this time.
2 - Wrap all shortcodes in a div with a specific class before displaying and toggle that class onclick of the button in the kitchen sink.
For both ways I need to get the content before displaying it in TinyMCE so that I can modify it. Unable to do so .. please help.
P.S: this needs to be done in a plugin. cannot modify core wordpress files.

You could use the tinymce param "setup" and create a onBeforeSetContent handler.
This way you can modify the content before it gegts into the editor and perform Action 2.

Related

Wordpress changable text in custom html

I have a custom page (page-news.php) and I styled it. Now I need to change some texts, and I dont want to do this in hardcoded page-news.php but I want to be able to change that in Wordpress, without go to code. Did you have maybe some ideas how to do this?
Here is visualization of how I think it should work (the only thing I can change would be white custom-text with section-1,section-2 and section-3) and I will be do this in wp-admin > pages >news:
Any ideas? I will be grateful for answer
Use ACF plugin. After installation, you can create custom fields and define their types. In your case, you should create 3 editor field or textarea and attach them to you page. When you visit wp-admin>pages>news you'll see these fields. Use get_field($fieldSlug) in your page template to show the values.

Allow page text to be edited from inside the wordpress menu without hardcoding it

New to WordPress theme design, and my google searching is not returning what I am after.
I have a theme I have created and its fine, but the text is all hardcoded into the theme.
I want there to be options in the theme appearance settings? (right place?) where a user can e.g. enter their 'about us' text.
But I have no idea what I should be searching or how to pull in that information into my theme.
Im no a beginner to PHP, but just the way WordPress works itself.
A link, search term or quick start is all I need.
I think you might find the (Free) Advanced Custom Fields plugin useful: http://www.advancedcustomfields.com/
You can add unlimited custom fields and create user interfaces for non-technical people to add content to your theme without them touching any code.
If you set up a field named 'about_text', calling it in your theme would look like this:
<?php the_field('about_text'); ?>
First, you should learn how wordpress is working to display the content. In back office, under Settings > Reading you'll find an option that let you tell how you want Wordpress to deal with the front page : is it a listing of the posts, or a static page?
If you choose the first options, it will use the index.php template from your theme folder. If it's a static page, you'll have to select which page to use for displaying the home (a page you created under the Menu page). The template that will be use then is front-page.php.
For every post / page (page is a post_type, just a variation of post) there will be a title field, a wysiwyg content and a featured image which will be displayed in a template. That's all you can manage by default. To display the title you can use the_title, the content the_content and for the featured image you will need the_post_thumbnail - note that those functions will need to be used inside the loop.
In order to display some more fun, you have many tools at your disposal:
Widgets : widgets are displayed in a sidebar - don't take it literally, it's just a zone of your template. You can register a sidebar with register_sidebar (use this inside your functions.php file, within an init hook). Then in your template you can display the sidebar with dynamic_sidebar.
In WP back office, go then under Appearence > Widgets. You will find your brand new sidebar where you can put any kind of widget you want. If you need a wysiwyg widget, I recommend you to install the Black Studio TinyMCE widget.
Custom fields : any post_type (a post type is an entry in wp_posts) in Wordpress have some associated metas store in wp_postmeta. A meta is defined by a key and a value - it's like any post have an associated array that you can customize.
There is two ways to work with custom fields. First, you can use the default Wordpress feature: when editing a page, click on the screen options button on the top right and enable "custom fields". You will now have a new area to work with on the bottom of the page : you can add fields by name (by default it will list the existing fields names but you can add your own) and value. It's good enough to simple text fields. Then in your template, you can get that value with the get_post_meta function.
The other way is to use a custom fields plugin, which allow you to have wysiwyg fields, loops, media uploader, datepicker... Two popular plugins are Advanced Custom Fields and Custom Field Suite. They both allow you to easily create set of fields for any page / post_type from the back office, and provide their own functions to manipulate fields in templates (but you can still use the WP functions if you want). For example, to get a custom field with Custom Field Suite you do: CFS()->get('my_custom_field').
Custom Post Types : sometimes, custom fields and widgets are not really convenient when you deal with a lot of data with possibly associated pages. In that cases, you can create your own post types just like posts or pages, but you can define which capabilities they have. Use register_post_type to define your new post type (still in init hook), that will make a new section available in your back office, just like posts. Then in your template you can query them with get_posts, the WP function that you will probably the most use when you'll start to play with Wordpress. I suggest you to read the WP_Query documentation in order to learn more about it.
And, at last but not least, you can create your own template that you can associate with any pages. For that, create a php file named whatever you want in your theme folder, paste into it the content from page.php and add this PHP comment on top :
/*
Template Name: My Template
*/
Then choose this template in the dropdown when you edit a page (on the right sidebar).
I think you will have enough to play with, but if you want learn more I recommend you to read about Wordpress hooks and the Widget API to create your own widgets.
Have fun with Wordpress!

How to output html on a custom location with a wordpress plugin?

How can I use a self-made Wordpress plugin to output for example a custom menu or custom HTML to a specific location? The only places I managed to output content is in wp_head and wp_footer, but is it possible to get content to show up anywhere else? Is it even possible to force the plugin to output the HTML for example inside a specific div or a DOM element?
Example scenarios
I want to add a custom button that triggers a menu or modal, but the button needs to be located inside the header and I also need a place for the modal HTML before the footer (example).
I want to add custom made "social share buttons" to every page and need a place to output the HTML after the page title.
Just to give you a feeling of what I'm trying to do...
Maybe I'm just way off track. I am new to this, but I am eager to learn.
"Teach me the ways of the force"
Appreciate any help, Thanks :)

Append custom class to wordpress headway theme

I would like to hack headway theme by adding an option to pages to append custom "classes" for that particular page. It's similar to your regular page where you have an option to select page template. but instead of selecting page template user would just have to select the class he/she wanted to append on the page. that class will have a CSS overide.
Example:
HTML
<body class=" red ...other headway css classes..." ">
CSS
body.red #container { background: red }
body.green #container { background: green }
I want to add a custom dropdown that list some classes option for theme to choose. example item on the dropdown. "red theme", "blue theme". This can also be done using Custom field but prefred to use dropdown so user won't get it wrong.
Append the class that was selected on the page to the tag of that page. I tried using "body_class" on my functions.php But It totally erased all the classes causing my page to break appart. What I wanted to do is just append the custom class instead of erasing the entire classes of the body.
Please advice. thanks!
Headway already has a custom meta box for custom classes on a page, so maybe you could either:
hack that to display a drop down
create some sort of meta box that will save a selection from a drop down to the same field that Headway writes to, if that's possible, and just remove/hide the Headway meta box from the admin
add an informational box on the page screen that displays the available classes and just use the Headway meta box instead (upgrade safe, best approach to keep things clean)

WordPress: Assigning widgets to individual pages

Are there any plugins or hacks that allow assigning widgets to individual pages?
EDIT:
Using self-hosted (.org) 2.8.4
An example of use would be: when you're editing a page in the admin, you'd ideally have the ability to assign widgets to that specific page. The default WP behavior is more "all or nothing" in that you assign widgets to the global sidebar and that's it... all pages get the exact same set of widgets... no "per page" assignment of widgets.
The Widget Logic plugin essentially achieves the desired result with a backwards approach, but it doesn't seem to work with the Rich Text Widget plugin.
There are several good ones. Display Widgets is my favorite. Widget Locationizer is perhaps more robust, but takes longer to manage. You can't go wrong with either one.
Finally found the Widget Context plugin which does what I need.
I don't know of any plugins that would give this functionality, but you might want to look at page templates here: WP Page Templates
With this route its more of a hack, as you can't use the CMS backend to manage your widgets. You would have to manually cut and paste the code of the widget into your page.
How about WP Page Widget:
Select widgets for each page / post / custom post type. For every
single page / post / custom post type we can select which widgets to
show.
This does it "the right way", i.e. when you edit a page you can choose which widgets to show on that page.

Categories