Wordpress [ ] tags? - wordpress

I'm very new at wordpress and I'm trying to understand a code from a friend. I went to his wordpress account and edit some test page. However, the page has code inside [ ] tags. How can I edit it?
Here is an example from the wordpress wdit page:
<p style="text-align: center;"><strong>Test- #1 Business Communication App For Project Management & Task Management</strong></p>
<strong>Important Notice:</strong> If you accessed ....</strong></em>, in order for your account to be properly updated.
[register_form]
How can I open/edit the [register_form] code?

This is a shortcode from a plugin or from your theme.
Edit
You can edit it in your theme. If the shortcode is from a plugin, you can overwrite it in your functions.php
function say(){
return "Hello World";
}
add_shortcode( 'register_form', 'say' );

are the tags used to call a function of some plugin that you have active. that specific tag I do not recognize what plugin is, I recommend Contact Form 7, it is easy to use.
If you want to create a PHP function and use it on your page, create a plugin and declare the call as you want. But! Be careful as an error however small will damage your page.
for add tag on wordpress, from your plugin.
function NAME_FUNCTION(){...}
add_shortcode( 'NAME_FUNCTION', 'NAME_TAG' );
and call
[NAME_TAG]

Related

Put some CSS style on single template page - Plugin WordPress

I'm developing my first WordPress plugin for an internship.
I know how to put style on the admin pages by wp_enqueue_style() and admin_enqueue_scripts. I also know wp_enqueue_scripts.
I created a custom post type to store businesses and a single template page in "templates" folder, called "single-myCPT.php".
The problem is: I don't understand how to call a css file for this single page.
The URL is like : mywebsite/myCPT/company
When I use the inspector and I go on "Network", there is no css file detected.
Sorry for my English, I'm a French guy who wants to improve that language :).
You can use wp_enqueue_style() and wp_enqueue_script() on front-end (non-admin) pages as well as admin pages.
Use the wp_enqueue_scripts action for the purpose.
function plugin_name_enqueue_frontend_style() {
wp_enqueue_style(
'plugin_name_frontend',
plugin_dir_url( __FILE__ ) . 'css/frontend.css');
}
add_action( 'wp_enqueue_scripts', 'plugin_name_enqueue_frontend_style' );
But, you should probably also include your frontend css on your admin page; you may need it.

How to call WordPress plugin function from custom page template?

I have a custom WordPress plugin that handles authentication.
There's a function logTheUserIn() inside plugin-name/src/Classes/Auth.php.
I need this function to be run when a user hits a custom WordPress template page (page-authPortal.php), which has this code at the top:
include_once('wp-includes/pluggable.php');
include_once("wp-content/plugins/ad-auth-bridge/src/Classes/Auth.php");
print "test";
I created a WordPress page titled "authPortal" and it shows the 'test' text, so I know the custom page is being loaded and rendered. Now I just need to fire off logTheUserIn().
I have tried adding shortcodes and actions inside Auth.php:
class Auth {
public function InitHooks() {
add_shortcode ('authNow', 'logTheUserIn');
add_action ('authAction', 'logTheUserIn');
I've then tried to use the actual shortcode [authNow] inside the WordPress editor, I have also tried do_shortcode and do_action.
What am I missing here?
Thank you!
There is no need to include or require the plugin fields. They are initially loaded by WordPress.
First, in your template, make sure your plugin is active and the function/class is reachable:
if ( function_exists( 'logTheUserIn') ) {
logTheUserIn();
}
Then fire the function right within your template.
In your case, you might need to check if class_exists, then initialize the class

WordPress using different CSS - is this possible?

Bit is a basic question here but can someone confirm that this statement be confirmed: WordPress Pages (certain templates created within) can pull different CSS and JS?
Or - does WordPress only permit universal CSS + JS to be pulled across the entire site?
Thanks for clearing this up.
Depends on what plugin and themes you use. The WordPress/PHP functions wp_enqueue_style() and wp_enqueue_script() can be used literally by everyone (core, themes, plugins, you) to request WordPress to load styles or JavaSctript. You can combine this with WordPress functions to check whether the current page is something you want to filter for (post type, post, front-page, category archive, template, etc.). Here is an example to load a custom style if on front page :
if (is_front_page()) {
wp_enqueue_style('custom-frontpage', 'my/path/to/frontpage.css');
}
You will have to hook this piece of code to the wp_enqueue_script action so that WordPress executes it at the appropriate time. Here is an example using an anonymous function:
add_action('wp_enqueue_scripts', function() {
if (is_front_page())
wp_enqueue_style('custom-frontpage', 'my/path/to/frontpage.css');
});
You can also register your code as a "normal" function and pass the functions name to add_action() instead.
Edit: Enabling and disabling plugins is a bit more difficult, since you can never know how they implement their features without examining the source code. Here are my thoughts on this:
The plugin likely uses the above method (wp_enqueue_styles, wp_enqueue_scripts) to register it's styles and scripts. The plugin, since it assumes to be needed on all pages and posts, does this on every page without the conditional checking described earlier.
You could do one of the following to stop the plugin from doing this:
Identify the place where the plugin loads the styles and scripts and add the if-statement to only do so if the post-ID matches your desired post-ID. This method is bad since your changes are lost every time the plugin is updated.
Write a "counter plugin" (you could just add it to your theme or find a plugin that allowes you to add PHP to your page) that "dequeues" the style and script added by the plugin with inversed conditional tag
The counter-plugin approach would look as follows:
function custom_unregister_plugin() {
if (not the desired blog post) {
wp_dequeue_style('my-plugin-stylesheet-handle');
wp_dequeue_script('my-plugin-script-handle');
}
}
Make sure this function is executed after the enqueuing-code of your plugin by giving it a low priority in the same hook (999 is just an example, test it yourself):
add_action('wp_enqueue_scripts', 'custom_unregister_plugin', 999);
With wp_enqueue_style() you can add stylesheet (https://developer.wordpress.org/reference/functions/wp_enqueue_style/)
You can use it after detecting which template is used
function enqueue_custom_stylesheet() {
if(get_page_template() == 'contact.php')
wp_enqueue_style( 'contact-style', get_template_directory_uri().'/contact.css' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_custom_stylesheet' );
You can use wp_enqueue_style for your CSS, wp_enqueue_script for your JS, wp_localize_script to pass variables from PHP to JS.
You can call these with hooks like:
funtion enqueue_my_stuff()
{
// your enqueue function calls
}
add_action('wp_enqueue_scripts','enqueue_my_stuff'); //front end
add_action('admin_enqueue_scripts','enqueue_my_stuff'); //admin panel
add_action('login_enqueue_scripts','enqueue_my_stuff'); //login screen

Wordpress plugin shortscodes in other plugins?

I'm developing a plugin that creates custom wordpress pages, however I ran into a problem when trying to get shortcodes from other plugins to integrate into my plugin, well more like I couldn't find any info on it.
For example if someone uses my custom page builder and adds a short code [gallery] that is associated with an enabled plugin, I want the shortcode to do it's thing.
Could anyone point me in the right direction for this?
Try wordpress
http://wordpress.org/plugins/synved-shortcodes/
while this plugin let's you integrate shortcodes on every wordpress page , I suppose that you issue is with wordpress functions.php file where you can have a look at , with this plugin installed !
You can check if a shortcode exist before printing it with the function shortcode_exists() (https://codex.wordpress.org/Function_Reference/shortcode_exists)
Example:
<?php
if ( shortcode_exists( 'gallery' ) ) {
// The [gallery] short code exists.
}
?>
Then, if it exist and you want to print that shortcode with PHP code you should use do_shortcode() function (https://developer.wordpress.org/reference/functions/do_shortcode/)
Example:
<?php echo do_shortcode('[gallery]); ?>
Always use in WordPress's in-built
the_content
hook to print your custom page content.
WordPress by default process all shortcodes before outputting any stuff from this hook.
More info can be found here: https://codex.wordpress.org/Function_Reference/the_content

How do I create a custom WordPress page?

I want my WordPress blog to have a page called music. On that page I will query the DB for posts with the category music and then change around the look and feel of the posts. So I can't just put a link to /categories/music/ because I want to do custom work on the posts.
Should I put this code in a separate php file and link to it? I think I may lose access to all the nice WordPress API calls if I do that.
I was thinking about using a filter, but I am not sure which one to use. I was thinking something like the following except the_title has not been grabbed yet so I cannot check the title.
function show_music(){
if( is_page() && the_title('','',false) == 'music' ){
echo "got here";
}
}
add_filter('pre_get_posts', 'show_portfolio');
How would you go about this?
You need to put the below code in the file, and then put the file in the Theme folder. Then you can create a page using Wordpress pages and select a page template with the name you put in this comment:
/*
Template Name: Something Goes Here
*/
You need to create custom page within your theme. If you dont have idea how to create custme page or template page in WordPress theme then view my easy tutorial How to create template page in WordPress

Resources