showing plugin in frontend of website or in page

末鹿安然 提交于 2019-12-08 06:24:19

问题


I want to show my plugin on my website or in page.. I using wordpress 2.3.2

I have given permission to folder also.

Example, there are one famous pluigin Holly dolly i edited that and updated , but i don't know how to show in front end..

I know i have to call

// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hello_dolly' );

but how?

I tried googling but didn't got any perfect solution..

Please help me..


回答1:


This is what i did-- copied hello.php file in plugin folder and renamed it as myhello.php . Here is the code working fine on my system --

<?php
/**
 * @package myhello
 * @version 1.6
 */
/*
Plugin Name: My Hello
Plugin URI: http://wordpress.org/extend/plugins/myhello/
Description: This is not just a plugin
Author: Swapnesh Sinha
Version: 1.6
Author URI: swapneshsinha.wordpress.com
*/

function myhello_get_lyric() {
    /** These are the lyrics to Hello Dolly */
    $lyrics = "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
Dolly'll never go away
Dolly'll never go away
Dolly'll never go away again";

    // Here we split it into lines
    $lyrics = explode( "\n", $lyrics );

    // And then randomly choose a line
    return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}

// This just echoes the chosen line, we'll position it later
function myhello() {
    $chosen = myhello_get_lyric();
    echo "<p id='dolly'>$chosen</p>";
}

// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'myhello' );

// We need some CSS to position the paragraph
function dolly_css() {
    // This makes sure that the positioning is also good for right-to-left languages
    $x = is_rtl() ? 'left' : 'right';

    echo "
    <style type='text/css'>
    #dolly {
        float: $x;
        padding-$x: 15px;
        padding-top: 5px;       
        margin: 0;
        font-size: 11px;
    }
    </style>
    ";
}

add_action( 'admin_head', 'dolly_css' );

?>


来源:https://stackoverflow.com/questions/10816046/showing-plugin-in-frontend-of-website-or-in-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!