WordPress.org

Ready to get started?Download WordPress

Forums

1st ever custom theme, but with issues? (17 posts)

  1. dpuk44
    Member
    Posted 4 months ago #

    Hi, I have just built my first working theme and am so excited. i am having a small issue regarding the text editor. it dosnt want to align images left or right.

    My 1st plan of attack was to copy the editor-style.css file from twentytwelve theme and link to in from my functions.php file like so

    // This theme styles the visual editor with editor-style.css to match the theme style.
    	add_editor_style('editor-style.css');

    but that didnt seem to work. The only way I could get it to work is to paste the following code into my main stylesheet style.css

    /* =WordPress Core
    -------------------------------------------------------------- */
    .alignnone {
        margin: 5px 20px 20px 0;
    }
    
    .aligncenter,
    div.aligncenter {
        display: block;
        margin: 5px auto 5px auto;
    }
    
    .alignright {
        float:right;
        margin: 5px 0 20px 20px;
    }
    
    .alignleft {
        float: left;
        margin: 5px 20px 20px 0;
    }
    
    .aligncenter {
        display: block;
        margin: 5px auto 5px auto;
    }
    
    a img.alignright {
        float: right;
        margin: 5px 0 20px 20px;
    }
    
    a img.alignnone {
        margin: 5px 20px 20px 0;
    }
    
    a img.alignleft {
        float: left;
        margin: 5px 20px 20px 0;
    }
    
    a img.aligncenter {
        display: block;
        margin-left: auto;
        margin-right: auto
    }
    
    .wp-caption {
        background: #fff;
        border: 1px solid #f0f0f0;
        max-width: 96%; /* Image does not overflow the content area */
        padding: 5px 3px 10px;
        text-align: center;
    }
    
    .wp-caption.alignnone {
        margin: 5px 20px 20px 0;
    }
    
    .wp-caption.alignleft {
        margin: 5px 20px 20px 0;
    }
    
    .wp-caption.alignright {
        margin: 5px 0 20px 20px;
    }
    
    .wp-caption img {
        border: 0 none;
        height: auto;
        margin: 0;
        max-width: 98.5%;
        padding: 0;
        width: auto;
    }
    
    .wp-caption p.wp-caption-text {
        font-size: 11px;
        line-height: 17px;
        margin: 0;
        padding: 0 4px 5px;
    }

    But surely there is a better way than this?

  2. esmi
    Forum Moderator
    Posted 4 months ago #

    Have you tried creating your own editor-style.css for your theme?

  3. dpuk44
    Member
    Posted 4 months ago #

    No, that doesn't work either?

  4. esmi
    Forum Moderator
    Posted 4 months ago #

    Why doesn't it work? It has always worked in all of the themes that I have created. Are you enqueing it correctly?

  5. Bryan Purcell
    Member
    Posted 4 months ago #

    I think you need to provide a full (or relative) URL to the add_editor_style function to get this to work - so you might use get_stylesheet_directory_uri or get_bloginf('siteurl') to get the URL of the site. Just make sure what you're putting into add_editor_style is something you could copy into the address bar of a web browser

  6. dpuk44
    Member
    Posted 4 months ago #

    Hi all, not sure where im going wrong or how to resolve this as I am a newbee to this. In my header I have:

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url') ?>">

    and then in my functions I have:

    add_editor_style('editor-style.css');

    and finally my editor-style.css I have:

    /* =WordPress Core
    -------------------------------------------------------------- */
    .alignnone {
        margin: 5px 20px 20px 0;
    }
    
    .aligncenter,
    div.aligncenter {
        display: block;
        margin: 5px auto 5px auto;
    }
    
    .alignright {
        float:right;
        margin: 5px 0 20px 20px;
    }
    
    .alignleft {
        float: left;
        margin: 5px 20px 20px 0;
    }
    
    .aligncenter {
        display: block;
        margin: 5px auto 5px auto;
    }
    
    a img.alignright {
        float: right;
        margin: 5px 0 20px 20px;
    }
    
    a img.alignnone {
        margin: 5px 20px 20px 0;
    }
    
    a img.alignleft {
        float: left;
        margin: 5px 20px 20px 0;
    }
    
    a img.aligncenter {
        display: block;
        margin-left: auto;
        margin-right: auto;
    }
    
    .wp-caption {
        background: #fff;
        border: 1px solid #f0f0f0;
        max-width: 96%; /* Image does not overflow the content area */
        padding: 5px 3px 10px;
        text-align: center;
    }
    
    .wp-caption.alignnone {
        margin: 5px 20px 20px 0;
    }
    
    .wp-caption.alignleft {
        margin: 5px 20px 20px 0;
    }
    
    .wp-caption.alignright {
        margin: 5px 0 20px 20px;
    }
    
    .wp-caption img {
        border: 0 none;
        height: auto;
        margin: 0;
        max-width: 98.5%;
        padding: 0;
        width: auto;
    }
    
    .wp-caption p.wp-caption-text {
        font-size: 11px;
        line-height: 17px;
        margin: 0;
        padding: 0 4px 5px;
    }
  7. Bryan Purcell
    Member
    Posted 4 months ago #

    Firstly - I'd recommend you place your "add_editor_style" call into the 'admin_init' action so you can be sure it's fired at the appropriate time. Secondly, can you verify that your website can access the file at editor-style.css?

    Visit: http://<your site url>/wp-content/themes/<your-theme-folder-name>/editor-style.css and make sure it loads? if not - can you verify permissions / file locations?

    Another thing to try - load up the new posts admin page (with the editor) and go to view source. you should be able to search the source for "editor-style" and see the one you're referring to in the tinymce code. If this isn't found - WP is not able to access that file for some reason.

    let me know how that looks.

    thanks!
    Bryan

  8. dpuk44
    Member
    Posted 4 months ago #

    Thanks Bryan, I'll give it ago and let you know

  9. dpuk44
    Member
    Posted 4 months ago #

    Hi Bryan,

    The only way I can get this working is to add the following to my main css file but surely this isnt correct is it?

    @import url("editor-style.css");

    Sorry im really confused and really stuck. I just want the changes I make in the back end text editor to show on my front end pages?

  10. Bryan Purcell
    Member
    Posted 4 months ago #

    Ok, yeah - we'll get this working! What's your live site URL?

  11. dpuk44
    Member
    Posted 3 months ago #

    Thanks mate. I've actually got it running of my local host, could that make a difference?

  12. Bryan Purcell
    Member
    Posted 3 months ago #

    Can you try this?

    load up the new posts admin page (with the editor) and go to view source in the browser. you should be able to search the source for "editor-style.css" and see the one you're referring to in the tinymce code.

    Is that in the source? This will tell us if the add_editor_style command is working, and that WP can find your file.

  13. dpuk44
    Member
    Posted 3 months ago #

    Hi mate, ok following your steps above I have found the following code:

    <script type="text/javascript">
    		tinyMCEPreInit = {
    			baseURL: "http://localhost/wordpress/wp-includes/js/tinymce",
    			suffix: ".min",
    			dragDropUpload: true,			mceInit: {'content':{theme:"modern",skin:"lightgray",language:"en",formats:{
    						alignleft: [
    							{selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'left'}},
    							{selector: 'img,table,dl.wp-caption', classes: 'alignleft'}
    						],
    						aligncenter: [
    							{selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'center'}},
    							{selector: 'img,table,dl.wp-caption', classes: 'aligncenter'}
    						],
    						alignright: [
    							{selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'right'}},
    							{selector: 'img,table,dl.wp-caption', classes: 'alignright'}
    						],
    						strikethrough: {inline: 'del'}
    					},relative_urls:false,remove_script_host:false,convert_urls:false,browser_spellcheck:true,fix_list_elements:true,entities:"38,amp,60,lt,62,gt",entity_encoding:"raw",keep_styles:false,paste_webkit_styles:"font-weight font-style color",preview_styles:"font-family font-size font-weight font-style text-decoration text-transform",wpeditimage_disable_captions:false,wpeditimage_html5_captions:false,plugins:"charmap,hr,media,paste,tabfocus,textcolor,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpview,wpfullscreen",content_css:"http://localhost/wordpress/wp-includes/css/dashicons.min.css?ver=3.9,http://localhost/wordpress/wp-includes/js/mediaelement/mediaelementplayer.min.css?ver=3.9,http://localhost/wordpress/wp-includes/js/mediaelement/wp-mediaelement.css?ver=3.9,http://localhost/wordpress/wp-includes/js/tinymce/skins/wordpress/wp-content.css?ver=3.9,http://localhost/wordpress/wp-content/themes/defaulttemplate//editor-style.css",selector:"#content",resize:false,menubar:false,wpautop:true,indent:false,toolbar1:"bold,italic,strikethrough,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,wp_fullscreen,wp_adv",toolbar2:"formatselect,underline,alignjustify,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help",toolbar3:"",toolbar4:"",tabfocus_elements:"insert-media-button,save-post",body_class:"content post-type-post post-status-auto-draft post-format-standard",add_unload_trigger:false}},
    			qtInit: {'content':{id:"content",buttons:"strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,fullscreen"},'replycontent':{id:"replycontent",buttons:"strong,em,link,block,del,ins,img,ul,ol,li,code,close"}},
    			ref: {plugins:"charmap,hr,media,paste,tabfocus,textcolor,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpview,wpfullscreen",theme:"modern",language:"en"},
    			load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
    		};
    		</script>
    		<script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/tinymce/wp-tinymce.php?c=1&ver=4021-20140412'></script>
    <script type='text/javascript'>
    tinymce.addI18n( 'en', {"New document":"New document","Formats":"Formats","Headings":"Headings","Heading 1":"Heading 1","Heading 2":"Heading 2","Heading 3":"Heading 3","Heading 4":"Heading 4","Heading 5":"Heading 5","Heading 6":"Heading 6","Blocks":"Blocks","Paragraph":"Paragraph","Blockquote":"Blockquote","Div":"Div","Pre":"Pre","Address":"Address","Inline":"Inline","Underline":"Underline","Strikethrough":"Strikethrough","Subscript":"Subscript","Superscript":"Superscript","Clear formatting":"Clear formatting","Bold":"Bold","Italic":"Italic","Code":"Code","Source code":"Source code","Font Family":"Font Family","Font Sizes":"Font Sizes","Align center":"Align center","Align right":"Align right","Align left":"Align left","Justify":"Justify","Increase indent":"Increase indent","Decrease indent":"Decrease indent","Cut":"Cut","Copy":"Copy","Paste":"Paste","Select all":"Select all","Undo":"Undo","Redo":"Redo","Ok":"OK","Cancel":"Cancel","Close":"Close","Visual aids":"Visual aids","Bullet list":"Bulleted list","Numbered list":"Numbered list","Square":"Square","Default":"Default","Circle":"Circle","Disc":"Disc","Lower Greek":"Lower Greek","Lower Alpha":"Lower Alpha","Upper Alpha":"Upper Alpha","Upper Roman":"Upper Roman","Lower Roman":"Lower Roman","Name":"Name","Anchor":"Anchor","Anchors":"Anchors","Document properties":"Document properties","Robots":"Robots","Title":"Title","Keywords":"Keywords","Encoding":"Encoding","Description":"Description","Author":"Author","Insert\/edit image":"Insert\/edit image","General":"General","Advanced":"Advanced","Source":"Source","Border":"Border","Constrain proportions":"Constrain proportions","Vertical space":"Vertical space","Image description":"Image description","Style":"Style","Dimensions":"Dimensions","Insert image":"Insert image","Insert date\/time":"Insert date\/time","Insert\/edit video":"Insert\/edit video","Poster":"Poster","Alternative source":"Alternative source","Paste your embed code below:":"Paste your embed code below:","Insert video":"Insert video","Embed":"Embed","Special character":"Special character","Right to left":"Right to left","Left to right":"Left to right","Emoticons":"Emoticons","Nonbreaking space":"Nonbreaking space","Page break":"Page break","Paste as text":"Paste as text","Preview":"Preview","Print":"Print","Save":"Save","Fullscreen":"Fullscreen","Horizontal line":"Horizontal line","Horizontal space":"Horizontal space","Restore last draft":"Restore last draft","Insert\/edit link":"Insert\/edit link","Remove link":"Remove link","Could not find the specified string.":"Could not find the specified string.","Replace":"Replace","Next":"Next","Prev":"Prev","Whole words":"Whole words","Find and replace":"Find and replace","Replace with":"Replace with","Find":"Find","Replace all":"Replace all","Match case":"Match case","Spellcheck":"Check Spelling","Finish":"Finish","Ignore all":"Ignore all","Ignore":"Ignore","Insert table":"Insert table","Delete table":"Delete table","Table properties":"Table properties","Row properties":"Table row properties","Cell properties":"Table cell properties","Row":"Row","Rows":"Rows","Column":"Column","Cols":"Cols","Cell":"Cell","Header cell":"Header cell","Header":"Header","Body":"Body","Footer":"Footer","Insert row before":"Insert row before","Insert row after":"Insert row after","Insert column before":"Insert column before","Insert column after":"Insert column after","Paste row before":"Paste table row before","Paste row after":"Paste table row after","Delete row":"Delete row","Delete column":"Delete column","Cut row":"Cut table row","Copy row":"Copy table row","Merge cells":"Merge table cells","Split cell":"Split table cell","Height":"Height","Width":"Width","Caption":"Caption","Alignment":"Alignment","Left":"Left","Center":"Center","Right":"Right","None":"None","Row group":"Row group","Column group":"Column group","Row type":"Row type","Cell type":"Cell type","Cell padding":"Cell padding","Cell spacing":"Cell spacing","Scope":"Scope","Insert template":"Insert template","Templates":"Templates","Background color":"Background color","Text color":"Text color","Show blocks":"Show blocks","Show invisible characters":"Show invisible characters","Words: {0}":"Words: {0}","Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.":"Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.\n\nIf you\u2019re looking to paste rich content from Microsoft Word, try turning this option off. The editor will clean up text pasted from Word automatically.","Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help":"Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help","You have unsaved changes are you sure you want to navigate away?":"The changes you made will be lost if you navigate away from this page.","Your browser doesn't support direct access to the clipboard. Please use the Ctrl+X\/C\/V keyboard shortcuts instead.":"Your browser does not support direct access to the clipboard. Please use the Ctrl+X\/C\/V keyboard shortcuts instead.","Insert":"Insert","File":"File","Edit":"Edit","Tools":"Tools","View":"View","Table":"Table","Format":"Format","Keyboard Shortcuts":"Keyboard Shortcuts","Toolbar Toggle":"Toolbar Toggle","Insert Read More tag":"Insert Read More tag","Distraction Free Writing":"Distraction Free Writing"});
    tinymce.ScriptLoader.markDone( 'http://localhost/wordpress/wp-includes/js/tinymce/langs/en.js' );
    </script>
  14. dpuk44
    Member
    Posted 3 months ago #

    Hi Bryan,

    OK think I may have sorted it at my template

    What I was doing was making changes in editor-style.css and expecting it to change on front end, but I read the following at WordPress CSS and I didnt realise that I had to include the WordPress Core styles within my style.css file

    /* =WordPress Core
    -------------------------------------------------------------- */
    .alignnone {
        margin: 5px 20px 20px 0;
    }
    
    .aligncenter,
    div.aligncenter {
        display: block;
        margin: 5px auto 5px auto;
    }
    
    .alignright {
        float:right;
        margin: 5px 0 20px 20px;
    }
    
    .alignleft {
        float: left;
        margin: 5px 20px 20px 0;
    }
    
    .aligncenter {
        display: block;
        margin: 5px auto 5px auto;
    }
    
    a img.alignright {
        float: right;
        margin: 5px 0 20px 20px;
    }
    
    a img.alignnone {
        margin: 5px 20px 20px 0;
    }
    
    a img.alignleft {
        float: left;
        margin: 5px 20px 20px 0;
    }
    
    a img.aligncenter {
        display: block;
        margin-left: auto;
        margin-right: auto
    }
    
    .wp-caption {
        background: #fff;
        border: 1px solid #f0f0f0;
        max-width: 96%; /* Image does not overflow the content area */
        padding: 5px 3px 10px;
        text-align: center;
    }
    
    .wp-caption.alignnone {
        margin: 5px 20px 20px 0;
    }
    
    .wp-caption.alignleft {
        margin: 5px 20px 20px 0;
    }
    
    .wp-caption.alignright {
        margin: 5px 0 20px 20px;
    }
    
    .wp-caption img {
        border: 0 none;
        height: auto;
        margin: 0;
        max-width: 98.5%;
        padding: 0;
        width: auto;
    }
    
    .wp-caption p.wp-caption-text {
        font-size: 11px;
        line-height: 17px;
        margin: 0;
        padding: 0 4px 5px;
    }

    I'm assuming thats what i was doing wrong?

  15. Bryan Purcell
    Member
    Posted 3 months ago #

    Hmm - yeah - styles in editor-styles.css will not appear on the frontend - that's only loaded when you're in the post editor. It looks like you're editor-styles.css is loading properly, given the snippet you posted. Are you seeing the styles in editor-styles.css manifested on the "Add New Post" page editor?

  16. dpuk44
    Member
    Posted 3 months ago #

    Hi mate, yeah I am seeing a border when I add border to the img properties in the css and it appears in the editor but not front end so that tells me the editor-style.css works. Thanks again and sorry for the confusion my end.

  17. Bryan Purcell
    Member
    Posted 3 months ago #

    Nice! Glad to hear it

Reply

You must log in to post.

About this Topic