最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Change font-size within a shortcode

programmeradmin4浏览0评论

I have a simple shortcode like this....

function myshortcode( $attributes, $content = null ) {
    extract( shortcode_atts( array(
        'class' => ''
    ), $attributes ) );
           return 'This is the content : ' . $content . ';
}
add_shortcode('my_shortcode', 'myshortcode');

This works great and if I use the following in a post...

[my_shortcode]This is the content that I want to display[/my_shortcode]

But what I want to do now is vary the font size of the content for example...

[my_shortcode]This is the [25px]content[/25px] that I want to display[/my_shortcode]

I want this to change the word 'content' to 25px font size.

Anyone know a way, maybe str_replace?

I have a simple shortcode like this....

function myshortcode( $attributes, $content = null ) {
    extract( shortcode_atts( array(
        'class' => ''
    ), $attributes ) );
           return 'This is the content : ' . $content . ';
}
add_shortcode('my_shortcode', 'myshortcode');

This works great and if I use the following in a post...

[my_shortcode]This is the content that I want to display[/my_shortcode]

But what I want to do now is vary the font size of the content for example...

[my_shortcode]This is the [25px]content[/25px] that I want to display[/my_shortcode]

I want this to change the word 'content' to 25px font size.

Anyone know a way, maybe str_replace?

Share Improve this question edited Mar 14, 2014 at 18:00 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Mar 14, 2014 at 17:48 fightstarr20fightstarr20 1,1358 gold badges26 silver badges47 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Are you trying to put a shortcode within a shortcode? Perhaps this is an easier solution to control your front-end output?

CSS

span.my_pixel_size{font-size:25px;}

PHP

'<p>This is the content: <span class="my_pixel_size">' . $content . '</span></p>';

From my understanding of shortcodes, you would need to create a shortcode for each pixel. It would be much easier to define a single shortcode, then use attributes to define a font-size.

function font_callback( $attributes, $content = null ) {
    extract( shortcode_atts( array(
        'size'  => '12px'
    ), $attributes ) );

    return '<span style="font-size:' . $size . '">' . $content . '</span>';
}
add_shortcode( 'font', 'font_callback' );

Then you can say something like:

This is the [font size="18px"]content[/font] that I want to display

This of course could be expanded upon to include font-family, classes, and an id.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论